1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_window.c,v $
37 * Date : $Date: 2003/09/22 16:09:02 $
38 * Version : $Revision: 1.5 $
39 * CVS Id : $Id: imgPrc_window.c,v 1.5 2003/09/22 16:09:02 tony Exp $
40 *
41 * Author : Legacy TINA
42 */
43
44 /**
45 * @file
46 * @brief Clamping image values to a given range of values. For display only.
47 *
48 */
49
50 #include "imgPrc_window.h"
51
52 #if HAVE_CONFIG_H
53 #include <config.h>
54 #endif
55
56 #include <math.h>
57 #include <tina/sys/sysDef.h>
58 #include <tina/sys/sysPro.h>
59 #include <tina/math/mathDef.h>
60 #include <tina/math/mathPro.h>
61 #include <tina/image/img_GenDef.h>
62 #include <tina/image/img_GenPro.h>
63
64
65 Imrect *imi_window(Imrect * im1, double thresh, double constant)
66 {
67 Imrect *im2;
68 Imregion *roi;
69 int *row1, *row2;
70 int lx, ux, ly, uy;
71 int i, j;
72
73 if (im1 == NULL)
74 return (NULL);
75
76 roi = im1->region;
77 if (roi == NULL)
78 return (NULL);
79 lx = roi->lx;
80 ux = roi->ux;
81 ly = roi->ly;
82 uy = roi->uy;
83
84 im2 = im_alloc(im1->height, im1->width, roi, int_v);
85 row1 = ivector_alloc(lx, ux);
86 row2 = ivector_alloc(lx, ux);
87
88 for (i = ly; i < uy; ++i)
89 {
90 im_get_row(row1, im1, i, lx, ux);
91 for (j = lx; j < ux; ++j)
92 if (row1[j] < thresh)
93 row2[j] = (int) thresh;
94 else if (row1[j] > thresh + constant)
95 row2[j] = (int) (thresh + constant);
96 else
97 row2[j] = row1[j];
98 im_put_row(row2, im2, i, lx, ux);
99 }
100
101 ivector_free(row1, lx);
102 ivector_free(row2, lx);
103 return (im2);
104 }
105
106 Imrect *imf_window(Imrect * im1, double thresh, double constant)
107 {
108 Imrect *im2;
109 Imregion *roi;
110 float *row1, *row2;
111 int lx, ux, ly, uy;
112 int i, j;
113
114 if (im1 == NULL)
115 return (NULL);
116
117 roi = im1->region;
118 if (roi == NULL)
119 return (NULL);
120 lx = roi->lx;
121 ux = roi->ux;
122 ly = roi->ly;
123 uy = roi->uy;
124
125 im2 = im_alloc(im1->height, im1->width, roi, float_v);
126 row1 = fvector_alloc(lx, ux);
127 row2 = fvector_alloc(lx, ux);
128
129 for (i = ly; i < uy; ++i)
130 {
131 im_get_rowf(row1, im1, i, lx, ux);
132 for (j = lx; j < ux; ++j)
133 if (row1[j] < thresh)
134 row2[j] = (float) thresh;
135 else if (row1[j] > thresh + constant)
136 row2[j] = (float) (thresh + constant);
137 else
138 row2[j] = row1[j];
139
140 im_put_rowf(row2, im2, i, lx, ux);
141 }
142
143 fvector_free(row1, lx);
144 fvector_free(row2, lx);
145 return (im2);
146 }
147
148
149 Imrect *im_window(Imrect * im, double thresh, double constant)
150 {
151 if (im == NULL)
152 return (NULL);
153 switch (im->vtype)
154 {
155 case uchar_v:
156 case char_v:
157 case short_v:
158 case ushort_v:
159 case int_v:
160 return (imi_window(im, thresh, constant));
161 case float_v:
162 return (imf_window(im, thresh, constant));
163 case complex_v:
164 default:
165 return (NULL);
166 }
167 }
168
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.