BRL-CAD
Loading...
Searching...
No Matches
ops.h
Go to the documentation of this file.
1/* I C V . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2011-2026 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
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
146
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. Output endpoints map to input endpoints; a one-pixel output
168 * maps to source coordinate zero.
169 * e.g. icv_resize(bif, ICV_RESIZE_NINTERP,1024,1024,0);
170 * interpolates the output image to have the size of 1024X1024.
171 *
172 * d) ICV_RESIZE_BINTERP : This interpolates using bilinear
173 * Interpolation Method. Output endpoints map to input endpoints; a
174 * one-pixel output maps to source coordinate zero. Stretching one
175 * dimension while shrinking the other is supported.
176 * e.g. icv_resize(bif, ICV_RESIZE_BINTERP,1024,1024,0);
177 * interpolates the output image to have the size of 1024X1024.
178 *
179 * resizes the image inplace.
180 *
181 * @param bif Image (packed in icv_image struct)
182 * @param method One of the modes.
183 * @param out_width Out Width.
184 * @param out_height Out Height.
185 * @param factor Integer type data representing the factor to be
186 * shrunken
187 * @return 0 on success and -1 on failure.
188 */
190
191/**
192 * Rotate an image.
193 * %s [-rifb | -a angle] [-# bytes] [-s squaresize] [-w width] [-n height] [-o outputfile] inputfile [> outputfile]
194 *
195 */
196ICV_EXPORT extern int icv_rot(size_t argc, const char *argv[]);
197
198/**
199 * Compare two images and report pixel differences. Return code is 1 if there
200 * are any differences, else 0. For more detailed reporting, pass non-null
201 * integer pointers to the matching, off_by_1, and/or off_by_many parameters.
202 *
203 * Counts are per-channel (matching pixdiff "bytes" semantics):
204 * - matching = number of channel bytes with identical values across both images
205 * - off_by_1 = number of channel bytes differing by exactly 1
206 * - off_by_many = number of channel bytes differing by more than 1
207 */
209
210/**
211 * Generate a visual representation of the differences between two images.
212 * (At least for now, images must be the same size.)
213 *
214 * For pixels that match, a half-intensity greyscale representation is output.
215 * For pixels that differ, each channel is independently highlighted:
216 * - channel byte values differ by exactly 1 → 0xC0 for that channel
217 * - channel byte values differ by more than 1 → 0xFF for that channel
218 * - channel byte values are equal → 0x00 for that channel
219 *
220 * This means a pixel that differs only in the red channel appears as a pure
221 * red highlight, green-only difference as pure green, etc. – matching the
222 * traditional pixdiff output convention.
223 *
224 * Returns NULL if there is an error.
225 */
227
228/**
229 * Compare two images using perceptual image hashing and report the Hamming
230 * distance between them. Useful for approximate image comparisons.
231 */
233
234/**
235 * Compare two images using approximate techniques.
236 */
237#define ICV_DIFF_PHASH 0
238#define ICV_DIFF_SSIM 1
240
241/**
242 * Compare the embedded render metadata (icv_render_info) of two images.
243 *
244 * Writes a human-readable report to @p out_msgs describing any differences
245 * found in the db filename, object list, and camera parameters.
246 *
247 * Returns 0 if the metadata in both images is identical (or both absent),
248 * 1 if they differ, and -1 if neither image carries any metadata.
249 *
250 * @param img1 First image (may be NULL – treated as having no metadata)
251 * @param img2 Second image (may be NULL – treated as having no metadata)
252 * @param out_msgs bu_vls to receive the human-readable comparison report; may be NULL
253 */
255
256/**
257 * Generate nirt shotline commands for every pixel that differs between
258 * @p img1 and @p img2.
259 *
260 * A separate nirt script is written for each image that has render_info
261 * attached. Both scripts encode shotlines for the same set of differing
262 * pixels; they differ only in the camera parameters used to reconstruct the
263 * rays and in the scene header comment. This allows the caller to
264 * interrogate either scene independently even when the images were rendered
265 * from different .g files or with different object sets.
266 *
267 * Ray reconstruction mirrors BRL-CAD rt/grid.c grid_setup() for the
268 * orthographic case (rt_perspective == 0). Perspective is also handled.
269 *
270 * Either output file pointer may be NULL to suppress that output. If an
271 * image has no render_info the corresponding output is silently skipped.
272 *
273 * @param img1 First image
274 * @param img2 Second image
275 * @param nirt_out1 Open FILE* to write img1's nirt script (may be NULL)
276 * @param nirt_out2 Open FILE* to write img2's nirt script (may be NULL)
277 *
278 * Returns the number of differing pixels for which shots were written, or -1
279 * on error (e.g., neither active output has render metadata, mismatched sizes).
280 */
282 FILE *nirt_out1, FILE *nirt_out2);
283
284/**
285 * Fit an image to suggested dimensions.
286 */
287ICV_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);
288
289/** @} */
290
292
293#endif /* ICV_OPS_H */
294
295/*
296 * Local Variables:
297 * tab-width: 8
298 * mode: C
299 * indent-tabs-mode: t
300 * c-file-style: "stroustrup"
301 * End:
302 * ex: shiftwidth=4 tabstop=8
303 */
Definition dvec.h:74
Header file for the BRL-CAD common definitions.
#define DEPRECATED
Definition common.h:433
icv_image_t * icv_multiply(icv_image_t *img1, icv_image_t *img2)
int icv_multiply_val(icv_image_t *img, double val)
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)
int icv_diff_nirt_shots(const icv_image_t *img1, const icv_image_t *img2, FILE *nirt_out1, FILE *nirt_out2)
fastf_t icv_adiff(icv_image_t *img1, icv_image_t *img2, int m)
int icv_diff_render_info(const icv_image_t *img1, const icv_image_t *img2, struct bu_vls *out_msgs)
DEPRECATED 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)
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_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_sub(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_diffimg(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:333
Definition vls.h:53
fundamental vector, matrix, quaternion math macros