BRL-CAD
ops.h
Go to the documentation of this file.
1 /* I C V . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2011-2024 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup icv_ops
21  *
22  * Various routines to perform operations on images.
23  *
24  */
25 
26 #ifndef ICV_OPS_H
27 #define ICV_OPS_H
28 
29 #include "common.h"
30 #include <stddef.h> /* for size_t */
31 #include "vmath.h"
32 #include "bu/vls.h"
33 #include "icv/defines.h"
34 
35 __BEGIN_DECLS
36 
37 /** @{ */
38 /** @file icv/ops.h */
39 
40 /**
41  * This function sanitizes the image.
42  *
43  * It forces the image pixels to be in the prescribed range.
44  *
45  * All the pixels higher than the max range are set to MAX (1.0).
46  * All the pixels lower than the min range are set to MIN (0.0).
47  *
48  * Note if an image(bif) is sanitized then,
49  * (bif->flags&&ICV_SANITIZED) is true.
50  *
51  */
52 ICV_EXPORT int icv_sanitize(icv_image_t* img);
53 
54 /**
55  * This adds a constant value to all the pixels of the image. Also if
56  * the flag ICV_OPERATIONS_MODE is set this doesn't sanitize the
57  * image.
58  *
59  * Note to set the flag for a bif (icv_image struct);
60  * bif->flags |= ICV_OPERATIONS_MODE;
61  *
62  */
63 ICV_EXPORT int icv_add_val(icv_image_t* img, double val);
64 
65 /**
66  * This multiplies all the pixels of the image with a constant Value.
67  * Also if the flag ICV_OPERATIONS_MODE is set this doesn't sanitize
68  * the image.
69  */
70 ICV_EXPORT int icv_multiply_val(icv_image_t* img, double val);
71 
72 /**
73  * This divides all the pixels of the image with a constant Value.
74  * Also if the flag ICV_OPERATIONS_MODE is set this doesn't sanitize
75  * the image.
76  */
77 ICV_EXPORT int icv_divide_val(icv_image_t* img, double val);
78 
79 /**
80  * This raises all the pixels of the image to a constant exponential
81  * power. Also if the flag ICV_OPERATIONS_MODE is set this doesn't
82  * sanitize the image.
83  */
84 ICV_EXPORT int icv_pow_val(icv_image_t* img, double val);
85 
86 /**
87  * This routine adds pixel value of one image to pixel value of other
88  * pixel and inserts in the same index of the output image.
89  *
90  * Also it sanitizes the image.
91  */
92 ICV_EXPORT icv_image_t *icv_add(icv_image_t *img1, icv_image_t *img2);
93 
94 /**
95  * This routine subtracts pixel value of one image from pixel value of
96  * other pixel and inserts the result at the same index of the output
97  * image.
98  *
99  * Also it sanitizes the image.
100  *
101  * @param img1 First Image.
102  * @param img2 Second Image.
103  * @return New icv_image (img1 - img2)
104  *
105  */
106 ICV_EXPORT icv_image_t *icv_sub(icv_image_t *img1, icv_image_t *img2);
107 
108 /**
109  * This routine multiplies pixel value of one image to pixel value of
110  * other pixel and inserts the result at the same index of the output
111  * image.
112  *
113  * Also it sanitizes the image.
114  *
115  * @param img1 First Image.
116  * @param img2 Second Image.
117  * @return New icv_image (img1 * img2)
118  *
119  */
121 
122 /**
123  * This routine divides pixel value of one image from pixel value of
124  * other pixel and inserts the result at the same index of the output
125  * image.
126  *
127  * Also it sanitizes the image.
128  *
129  * @param img1 First Image.
130  * @param img2 Second Image.
131  * @return New icv_image (img1 / img2)
132  *
133  */
134 ICV_EXPORT icv_image_t *icv_divide(icv_image_t *img1, icv_image_t *img2);
135 
136 /**
137  * Change the saturation of image pixels. If sat is set to 0.0 the
138  * result will be monochromatic; if sat is made 1.0, the color will
139  * not change; if sat is made greater than 1.0, the amount of color is
140  * increased.
141  *
142  * @param img RGB Image to be saturated.
143  * @param sat Saturation value.
144  */
145 ICV_EXPORT int icv_saturate(icv_image_t* img, double sat);
146 
147 typedef enum {
153 
154 /**
155  * This function resizes the given input image.
156  * Mode of usage:
157  * a) ICV_RESIZE_UNDERSAMPLE : This method undersamples the said image
158  * e.g. icv_resize(bif, ICV_RESIZE_UNDERSAMPLE, 0, 0, 2);
159  * undersamples the image with a factor of 2.
160  *
161  * b) ICV_RESIZE_SHRINK : This Shrinks the image, keeping the light
162  * energy per square area as constant.
163  * e.g. icv_resize(bif, ICV_RESIZE_SHRINK,0,0,2);
164  * shrinks the image with a factor of 2.
165  *
166  * c) ICV_RESIZE_NINTERP : This interpolates using nearest neighbor
167  * method.
168  * e.g. icv_resize(bif, ICV_RESIZE_NINTERP,1024,1024,0);
169  * interpolates the output image to have the size of 1024X1024.
170  *
171  * d) ICV_RESIZE_BINTERP : This interpolates using bilinear
172  * Interpolation Method.
173  * e.g. icv_resize(bif, ICV_RESIZE_BINTERP,1024,1024,0);
174  * interpolates the output image to have the size of 1024X1024.
175  *
176  * resizes the image inplace.
177  *
178  * @param bif Image (packed in icv_image struct)
179  * @param method One of the modes.
180  * @param out_width Out Width.
181  * @param out_height Out Height.
182  * @param factor Integer type data representing the factor to be
183  * shrunken
184  * @return 0 on success and -1 on failure.
185  */
186 ICV_EXPORT int icv_resize(icv_image_t *bif, ICV_RESIZE_METHOD method, size_t out_width, size_t out_height, size_t factor);
187 
188 /**
189  * Rotate an image.
190  * %s [-rifb | -a angle] [-# bytes] [-s squaresize] [-w width] [-n height] [-o outputfile] inputfile [> outputfile]
191  *
192  */
193 ICV_EXPORT extern int icv_rot(size_t argc, const char *argv[]);
194 
195 /**
196  * Compare two images and report pixel differences. Return code is 1 if there
197  * are any differences, else 0. For more detailed reporting, pass non-null
198  * integer pointers to the matching, off_by_1, and/or off_by_many parameters.
199  */
200 ICV_EXPORT extern int icv_diff(int *matching, int *off_by_1, int *off_by_many, icv_image_t *img1, icv_image_t *img2);
201 
202 /**
203  * Generate a visual representation of the differences between two images.
204  * (At least for now, images must be the same size.)
205  *
206  * Returns NULL if there is an error.
207  */
208 ICV_EXPORT extern icv_image_t *icv_diffimg(icv_image_t *img1, icv_image_t *img2);
209 
210 /**
211  * Compare two images using perceptual image hashing and report the Hamming
212  * distance between them. Useful for approximate image comparisons.
213  */
214 ICV_EXPORT extern uint32_t icv_pdiff(icv_image_t *img1, icv_image_t *img2);
215 
216 /**
217  * Fit an image to suggested dimensions.
218  */
219 ICV_EXPORT extern int icv_fit(icv_image_t *img, struct bu_vls *msg, size_t o_width_req, size_t o_height_req, fastf_t sf);
220 
221 /** @} */
222 
223 __END_DECLS
224 
225 #endif /* ICV_OPS_H */
226 
227 /*
228  * Local Variables:
229  * tab-width: 8
230  * mode: C
231  * indent-tabs-mode: t
232  * c-file-style: "stroustrup"
233  * End:
234  * ex: shiftwidth=4 tabstop=8
235  */
Header file for the BRL-CAD common definitions.
icv_image_t * icv_divide(icv_image_t *img1, icv_image_t *img2)
icv_image_t * icv_add(icv_image_t *img1, icv_image_t *img2)
int icv_multiply_val(icv_image_t *img, double val)
icv_image_t * icv_multiply(icv_image_t *img1, icv_image_t *img2)
int icv_add_val(icv_image_t *img, double val)
int icv_diff(int *matching, int *off_by_1, int *off_by_many, icv_image_t *img1, icv_image_t *img2)
int icv_rot(size_t argc, const char *argv[])
int icv_pow_val(icv_image_t *img, double val)
uint32_t icv_pdiff(icv_image_t *img1, icv_image_t *img2)
int icv_sanitize(icv_image_t *img)
int icv_fit(icv_image_t *img, struct bu_vls *msg, size_t o_width_req, size_t o_height_req, fastf_t sf)
int icv_saturate(icv_image_t *img, double sat)
int icv_resize(icv_image_t *bif, ICV_RESIZE_METHOD method, size_t out_width, size_t out_height, size_t factor)
icv_image_t * icv_diffimg(icv_image_t *img1, icv_image_t *img2)
int icv_divide_val(icv_image_t *img, double val)
ICV_RESIZE_METHOD
Definition: ops.h:147
icv_image_t * icv_sub(icv_image_t *img1, icv_image_t *img2)
@ ICV_RESIZE_UNDERSAMPLE
Definition: ops.h:148
@ ICV_RESIZE_SHRINK
Definition: ops.h:149
@ ICV_RESIZE_BINTERP
Definition: ops.h:151
@ ICV_RESIZE_NINTERP
Definition: ops.h:150
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:334
Definition: vls.h:53
fundamental vector, matrix, quaternion math macros