#ifndef rdo_image_H #define rdo_image_H #define rdo_image_H_COPYRIGHT "Copyright © 2008 Danillo Pereira and J. Stolfi, UNICAMP" /* Last edited on 2024-12-21 11:52:33 by stolfi */ /* Image tools. */ #include #include #include #include #include #include typedef float_image_t image_t; void rdo_image_find_max_min(image_t *img, float *vMin, float *vMax); /* Find the minimum value {*vMin} and the maximum value {*vMax} among all samples of all channels of {img}, ignoring {±INF}s and {NAN}s. */ void rdo_image_map_max_to_one(image_t *img); /* Scales every sample value of {img} so that zero remains zero and the maximum sample value becomes 1.0. Negative values will remain negative. Ignores sample values that are {NAN} or {±INF}. */ void rdo_image_map_zero_to_half(image_t *img); /* Scales every sample value of {img} so that zero becomes 0.500 and and all sample values (positive or negative) span the range {[0_1]}. Ignores sample values that are {NAN} or {±INF}. May insert a white pixels (value 1.000 in all channels) to guard against further normalization. */ void rdo_image_write(char *outDir, char *name, image_t *img, double expo); /* Writes the image {img} to a file called "{outDir}/{name}.{ext}" where {ext} is "pgm" if {img} has only one channel, or "ppm" if it has three channels. Normalizes the samples, preserving the value 0.0 and mapping the largest value to 1.0; then applies the power law encoding with decoding exponent {expo}. */ #define BT_EXPO sample_conv_gamma_BT709_ENC_EXPO #define BT_BIAS sample_conv_gamma_BT709_BIAS /* Values of {expo} and {bias} for {sample_conv_gamma} that approximate the BT.709 encoding. For decoding, use {1/BT_EXPO}. */ /* PIXEL INDICES AND IMAGE COORDINATES Points on the image are expressed in /image coordinates/ {H,V} used by most image processing tools, such as ImageMagick's {display} and the PBM package. The origin is at the TOP LEFT corner, with the {V} axis pointing{DOWN}; all coordinates are measured in pixels. A pixel is therefore a unit square with integer corners. The /indices/ {ih,iv} of the pixel are the {H,V} coordinates of its TOP LEFT corner. The center of that pixel has image coordiantes {ih+0.5, iv+0.5}. Note that the indices in a {float_image_t} have the vertical axis pointing UP. Therefore we will use {ix,iy} rather than {ih,iv} for indices into a {float_image_t}. */ void rdo_image_compute_pixel_center_coords(int ih, int iv, double *hP, double *vP); /* Returns the image coordinates {*hP,*vP} of the center of the pixel whose (standard) indices are {ih,iv}. */ void rdo_image_coords_to_pixel_indices(double h, double v, int *ihP, int *ivP); /* Returns the (standard) indices {*ihP,*ivP} of the pixel that contains the point with image coordinates {h,v}. */ /* PROJECTION COORDINATE SYSTEM The /projection coordinates/ {X,Y} have the origin on the optical axis, with the {Y} axis pointing UP, and their units are such that the whole image is inscribed in the unit circle. */ void rdo_image_coords_to_projection_coords(double h, double v, int nh, int nv, double *xP, double *yP); /* Computes the projection coordinates {*xP,*yP} of the point on the image whose (standard) image coordinates are {h,v}. Note that {*yP} decreases when {v} increases. Assumes that the image has {nh} columns and {nv} rows of square pixels. */ void rdo_image_coords_from_projection_coords(double x, double y, int nh, int nv, double *hP, double *vP); /* Computes the (standard) image coordinates {*hP,*vP} of the point on the image whose projection coordinates are {x,y}. Note that {*hP} decreases when {y} increases. Assumes that the image has {nh} columns and {nv} rows of square pixels. */ #endif