00001
00002 #include "vepl_dyadic.h"
00003 #include <vepl/accessors/vipl_accessors_vil_image_view_base.h>
00004 #include <vipl/vipl_dyadic.h>
00005 #include <vil/vil_image_view.h>
00006 #include <vil/vil_pixel_format.h>
00007 #include <vil/vil_rgb.h>
00008 #include <vxl_config.h>
00009
00010 #define r_g_b vil_rgb<vxl_byte> // cannot use typedef since that may cause ambiguous overload problems
00011 void sum_ubyte(vxl_byte& a, vxl_byte const& b) { a += b; }
00012 void sum_short(vxl_uint_16& a, vxl_uint_16 const& b) { a += b; }
00013 void sum_int(vxl_uint_32& a, vxl_uint_32 const& b) { a += b; }
00014 void sum_rgb(r_g_b& a, r_g_b const& b) { a.r += b.r; a.g += b.g; a.b += b.b; }
00015 void sum_float(float& a, float const& b) { a += b; }
00016 void sum_double(double& a, double const& b) { a += b; }
00017 void dif_ubyte(vxl_byte& a, vxl_byte const& b) { a -= b; }
00018 void dif_short(vxl_uint_16& a, vxl_uint_16 const& b) { a -= b; }
00019 void dif_int(vxl_uint_32& a, vxl_uint_32 const& b) { a -= b; }
00020 void dif_rgb(r_g_b& a, r_g_b const& b) { a.r -= b.r; a.g -= b.g; a.b -= b.b; }
00021 void dif_float(float& a, float const& b) { a -= b; }
00022 void dif_double(double& a, double const& b) { a -= b; }
00023 void min_ubyte(vxl_byte& a, vxl_byte const& b) { if (b<a) a = b; }
00024 void min_short(vxl_uint_16& a, vxl_uint_16 const& b) { if (b<a) a = b; }
00025 void min_int(vxl_uint_32& a, vxl_uint_32 const& b) { if (b<a) a = b; }
00026 void min_float(float& a, float const& b) { if (b<a) a = b; }
00027 void min_double(double& a, double const& b) { if (b<a) a = b; }
00028 void max_ubyte(vxl_byte& a, vxl_byte const& b) { if (a<b) a = b; }
00029 void max_short(vxl_uint_16& a, vxl_uint_16 const& b) { if (a<b) a = b; }
00030 void max_int(vxl_uint_32& a, vxl_uint_32 const& b) { if (a<b) a = b; }
00031 void max_float(float& a, float const& b) { if (a<b) a = b; }
00032 void max_double(double& a, double const& b) { if (a<b) a = b; }
00033
00034 void vepl_dyadic_sum(vil_image_resource_sptr im_out, vil_image_resource_sptr image)
00035 {
00036
00037 if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00038 vil_image_view<vxl_byte> in = image->get_view();
00039 vil_image_view<vxl_byte> out = im_out->get_view();
00040 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte> op(sum_ubyte);
00041 op.put_in_data_ptr(&in);
00042 op.put_out_data_ptr(&out);
00043 op.filter();
00044 }
00045
00046
00047 else if (image->pixel_format() == VIL_PIXEL_FORMAT_RGB_BYTE) {
00048 vil_image_view<r_g_b > in = image->get_view();
00049 vil_image_view<r_g_b > out = im_out->get_view();
00050 vipl_dyadic<vil_image_view_base,vil_image_view_base,r_g_b ,r_g_b > op(sum_rgb);
00051 op.put_in_data_ptr(&in);
00052 op.put_out_data_ptr(&out);
00053 op.filter();
00054 }
00055
00056
00057 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_16) {
00058 vil_image_view<vxl_uint_16> in = image->get_view();
00059 vil_image_view<vxl_uint_16> out = im_out->get_view();
00060 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_16,vxl_uint_16> op(sum_short);
00061 op.put_in_data_ptr(&in);
00062 op.put_out_data_ptr(&out);
00063 op.filter();
00064 }
00065
00066
00067 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_32) {
00068 vil_image_view<vxl_uint_32> in = image->get_view();
00069 vil_image_view<vxl_uint_32> out = im_out->get_view();
00070 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_32,vxl_uint_32> op(sum_int);
00071 op.put_in_data_ptr(&in);
00072 op.put_out_data_ptr(&out);
00073 op.filter();
00074 }
00075
00076
00077 else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00078 vil_image_view<float> in = image->get_view();
00079 vil_image_view<float> out = im_out->get_view();
00080 vipl_dyadic<vil_image_view_base,vil_image_view_base,float,float> op(sum_float);
00081 op.put_in_data_ptr(&in);
00082 op.put_out_data_ptr(&out);
00083 op.filter();
00084 }
00085
00086
00087 else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00088 vil_image_view<double> in = image->get_view();
00089 vil_image_view<double> out = im_out->get_view();
00090 vipl_dyadic<vil_image_view_base,vil_image_view_base,double,double> op(sum_double);
00091 op.put_in_data_ptr(&in);
00092 op.put_out_data_ptr(&out);
00093 op.filter();
00094 }
00095
00096
00097 else
00098 vcl_cerr << __FILE__ ": vepl_dyadic_sum() not implemented for " << image << '\n';
00099 }
00100
00101 void vepl_dyadic_dif(vil_image_resource_sptr im_out, vil_image_resource_sptr image)
00102 {
00103
00104 if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00105 vil_image_view<vxl_byte> in = image->get_view();
00106 vil_image_view<vxl_byte> out = im_out->get_view();
00107 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte> op(dif_ubyte);
00108 op.put_in_data_ptr(&in);
00109 op.put_out_data_ptr(&out);
00110 op.filter();
00111 }
00112
00113
00114 else if (image->pixel_format() == VIL_PIXEL_FORMAT_RGB_BYTE) {
00115 vil_image_view<r_g_b > in = image->get_view();
00116 vil_image_view<r_g_b > out = im_out->get_view();
00117 vipl_dyadic<vil_image_view_base,vil_image_view_base,r_g_b ,r_g_b > op(dif_rgb);
00118 op.put_in_data_ptr(&in);
00119 op.put_out_data_ptr(&out);
00120 op.filter();
00121 }
00122
00123
00124 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_16) {
00125 vil_image_view<vxl_uint_16> in = image->get_view();
00126 vil_image_view<vxl_uint_16> out = im_out->get_view();
00127 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_16,vxl_uint_16> op(dif_short);
00128 op.put_in_data_ptr(&in);
00129 op.put_out_data_ptr(&out);
00130 op.filter();
00131 }
00132
00133
00134 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_32) {
00135 vil_image_view<vxl_uint_32> in = image->get_view();
00136 vil_image_view<vxl_uint_32> out = im_out->get_view();
00137 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_32,vxl_uint_32> op(dif_int);
00138 op.put_in_data_ptr(&in);
00139 op.put_out_data_ptr(&out);
00140 op.filter();
00141 }
00142
00143
00144 else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00145 vil_image_view<float> in = image->get_view();
00146 vil_image_view<float> out = im_out->get_view();
00147 vipl_dyadic<vil_image_view_base,vil_image_view_base,float,float> op(dif_float);
00148 op.put_in_data_ptr(&in);
00149 op.put_out_data_ptr(&out);
00150 op.filter();
00151 }
00152
00153
00154 else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00155 vil_image_view<double> in = image->get_view();
00156 vil_image_view<double> out = im_out->get_view();
00157 vipl_dyadic<vil_image_view_base,vil_image_view_base,double,double> op(dif_double);
00158 op.put_in_data_ptr(&in);
00159 op.put_out_data_ptr(&out);
00160 op.filter();
00161 }
00162
00163
00164 else
00165 vcl_cerr << __FILE__ ": vepl_dyadic_dif() not implemented for " << image << '\n';
00166 }
00167
00168 void vepl_dyadic_min(vil_image_resource_sptr im_out, vil_image_resource_sptr image)
00169 {
00170
00171 if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00172 vil_image_view<vxl_byte> in = image->get_view();
00173 vil_image_view<vxl_byte> out = im_out->get_view();
00174 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte> op(min_ubyte);
00175 op.put_in_data_ptr(&in);
00176 op.put_out_data_ptr(&out);
00177 op.filter();
00178 }
00179
00180
00181 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_16) {
00182 vil_image_view<vxl_uint_16> in = image->get_view();
00183 vil_image_view<vxl_uint_16> out = im_out->get_view();
00184 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_16,vxl_uint_16> op(min_short);
00185 op.put_in_data_ptr(&in);
00186 op.put_out_data_ptr(&out);
00187 op.filter();
00188 }
00189
00190
00191 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_32) {
00192 vil_image_view<vxl_uint_32> in = image->get_view();
00193 vil_image_view<vxl_uint_32> out = im_out->get_view();
00194 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_32,vxl_uint_32> op(min_int);
00195 op.put_in_data_ptr(&in);
00196 op.put_out_data_ptr(&out);
00197 op.filter();
00198 }
00199
00200
00201 else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00202 vil_image_view<float> in = image->get_view();
00203 vil_image_view<float> out = im_out->get_view();
00204 vipl_dyadic<vil_image_view_base,vil_image_view_base,float,float> op(min_float);
00205 op.put_in_data_ptr(&in);
00206 op.put_out_data_ptr(&out);
00207 op.filter();
00208 }
00209
00210
00211 else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00212 vil_image_view<double> in = image->get_view();
00213 vil_image_view<double> out = im_out->get_view();
00214 vipl_dyadic<vil_image_view_base,vil_image_view_base,double,double> op(min_double);
00215 op.put_in_data_ptr(&in);
00216 op.put_out_data_ptr(&out);
00217 op.filter();
00218 }
00219
00220
00221 else
00222 vcl_cerr << __FILE__ ": vepl_dyadic_min() not implemented for " << image << '\n';
00223 }
00224
00225 void vepl_dyadic_max(vil_image_resource_sptr im_out, vil_image_resource_sptr image)
00226 {
00227
00228 if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00229 vil_image_view<vxl_byte> in = image->get_view();
00230 vil_image_view<vxl_byte> out = im_out->get_view();
00231 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_byte,vxl_byte> op(max_ubyte);
00232 op.put_in_data_ptr(&in);
00233 op.put_out_data_ptr(&out);
00234 op.filter();
00235 }
00236
00237
00238 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_16) {
00239 vil_image_view<vxl_uint_16> in = image->get_view();
00240 vil_image_view<vxl_uint_16> out = im_out->get_view();
00241 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_16,vxl_uint_16> op(max_short);
00242 op.put_in_data_ptr(&in);
00243 op.put_out_data_ptr(&out);
00244 op.filter();
00245 }
00246
00247
00248 else if (image->pixel_format() == VIL_PIXEL_FORMAT_UINT_32) {
00249 vil_image_view<vxl_uint_32> in = image->get_view();
00250 vil_image_view<vxl_uint_32> out = im_out->get_view();
00251 vipl_dyadic<vil_image_view_base,vil_image_view_base,vxl_uint_32,vxl_uint_32> op(max_int);
00252 op.put_in_data_ptr(&in);
00253 op.put_out_data_ptr(&out);
00254 op.filter();
00255 }
00256
00257
00258 else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00259 vil_image_view<float> in = image->get_view();
00260 vil_image_view<float> out = im_out->get_view();
00261 vipl_dyadic<vil_image_view_base,vil_image_view_base,float,float> op(max_float);
00262 op.put_in_data_ptr(&in);
00263 op.put_out_data_ptr(&out);
00264 op.filter();
00265 }
00266
00267
00268 else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00269 vil_image_view<double> in = image->get_view();
00270 vil_image_view<double> out = im_out->get_view();
00271 vipl_dyadic<vil_image_view_base,vil_image_view_base,double,double> op(max_double);
00272 op.put_in_data_ptr(&in);
00273 op.put_out_data_ptr(&out);
00274 op.filter();
00275 }
00276
00277
00278 else
00279 vcl_cerr << __FILE__ ": vepl_dyadic_max() not implemented for " << image << '\n';
00280 }
00281