00001
00002 #include "vepl1_dyadic.h"
00003 #include <vipl/accessors/vipl_accessors_vil1_image.h>
00004 #include <vipl/vipl_dyadic.h>
00005 #include <vil1/vil1_memory_image_of.h>
00006 #include <vil1/vil1_rgb.h>
00007 #include <vxl_config.h>
00008
00009 #define r_g_b vil1_rgb<vxl_byte> // cannot use typedef since that may cause ambiguous overload problems
00010 void sum_ubyte(vxl_byte& a, vxl_byte const& b) { a += b; }
00011 void sum_ushort(vxl_uint_16& a, vxl_uint_16 const& b) { a += b; }
00012 void sum_rgb(r_g_b& a, r_g_b const& b) { a.r += b.r; a.g += b.g; a.b += b.b; }
00013 void sum_float(float& a, float const& b) { a += b; }
00014 void sum_double(double& a, double const& b) { a += b; }
00015 void dif_ubyte(vxl_byte& a, vxl_byte const& b) { a -= b; }
00016 void dif_ushort(vxl_uint_16& a, vxl_uint_16 const& b) { a -= b; }
00017 void dif_rgb(r_g_b& a, r_g_b const& b) { a.r -= b.r; a.g -= b.g; a.b -= b.b; }
00018 void dif_float(float& a, float const& b) { a -= b; }
00019 void dif_double(double& a, double const& b) { a -= b; }
00020 void min_ubyte(vxl_byte& a, vxl_byte const& b) { if (b<a) a = b; }
00021 void min_ushort(vxl_uint_16& a, vxl_uint_16 const& b) { if (b<a) a = b; }
00022 void min_float(float& a, float const& b) { if (b<a) a = b; }
00023 void min_double(double& a, double const& b) { if (b<a) a = b; }
00024 void max_ubyte(vxl_byte& a, vxl_byte const& b) { if (a<b) a = b; }
00025 void max_ushort(vxl_uint_16& a, vxl_uint_16 const& b) { if (a<b) a = b; }
00026 void max_float(float& a, float const& b) { if (a<b) a = b; }
00027 void max_double(double& a, double const& b) { if (a<b) a = b; }
00028
00029 void vepl1_dyadic_sum(vil1_image im_out, vil1_image const& image)
00030 {
00031
00032 if (vil1_pixel_format(image) == VIL1_BYTE) {
00033 vil1_memory_image_of<vxl_byte> mem(image);
00034 im_out = mem;
00035 vipl_dyadic<vil1_image,vil1_image,vxl_byte,vxl_byte> op(sum_ubyte);
00036 op.put_in_data_ptr(&mem);
00037 op.put_out_data_ptr(&im_out);
00038 op.filter();
00039 }
00040
00041
00042 else if (vil1_pixel_format(image) == VIL1_RGB_BYTE) {
00043 vil1_memory_image_of<r_g_b > mem(image);
00044 im_out = mem;
00045 vipl_dyadic<vil1_image,vil1_image,r_g_b,r_g_b > op(sum_rgb);
00046 op.put_in_data_ptr(&mem);
00047 op.put_out_data_ptr(&im_out);
00048 op.filter();
00049 }
00050
00051
00052 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00053 vil1_memory_image_of<vxl_uint_16> mem(image);
00054 im_out = mem;
00055 vipl_dyadic<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(sum_ushort);
00056 op.put_in_data_ptr(&mem);
00057 op.put_out_data_ptr(&im_out);
00058 op.filter();
00059 }
00060
00061
00062 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00063 vil1_memory_image_of<float> mem(image);
00064 im_out = mem;
00065 vipl_dyadic<vil1_image,vil1_image,float,float> op(sum_float);
00066 op.put_in_data_ptr(&mem);
00067 op.put_out_data_ptr(&im_out);
00068 op.filter();
00069 }
00070
00071
00072 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00073 vil1_memory_image_of<double> mem(image);
00074 im_out = mem;
00075 vipl_dyadic<vil1_image,vil1_image,double,double> op(sum_double);
00076 op.put_in_data_ptr(&mem);
00077 op.put_out_data_ptr(&im_out);
00078 op.filter();
00079 }
00080
00081
00082 else {
00083 vcl_cerr << __FILE__ ": vepl1_dyadic_sum() not implemented for " << image << vcl_endl;
00084 }
00085 }
00086
00087 void vepl1_dyadic_dif(vil1_image im_out, vil1_image const& image)
00088 {
00089
00090 if (vil1_pixel_format(image) == VIL1_BYTE) {
00091 vil1_memory_image_of<vxl_byte> mem(image);
00092 im_out = mem;
00093 vipl_dyadic<vil1_image,vil1_image,vxl_byte,vxl_byte> op(dif_ubyte);
00094 op.put_in_data_ptr(&mem);
00095 op.put_out_data_ptr(&im_out);
00096 op.filter();
00097 }
00098
00099
00100 else if (vil1_pixel_format(image) == VIL1_RGB_BYTE) {
00101 vil1_memory_image_of<r_g_b > mem(image);
00102 im_out = mem;
00103 vipl_dyadic<vil1_image,vil1_image,r_g_b,r_g_b > op(dif_rgb);
00104 op.put_in_data_ptr(&mem);
00105 op.put_out_data_ptr(&im_out);
00106 op.filter();
00107 }
00108
00109
00110 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00111 vil1_memory_image_of<vxl_uint_16> mem(image);
00112 im_out = mem;
00113 vipl_dyadic<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(dif_ushort);
00114 op.put_in_data_ptr(&mem);
00115 op.put_out_data_ptr(&im_out);
00116 op.filter();
00117 }
00118
00119
00120 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00121 vil1_memory_image_of<float> mem(image);
00122 im_out = mem;
00123 vipl_dyadic<vil1_image,vil1_image,float,float> op(dif_float);
00124 op.put_in_data_ptr(&mem);
00125 op.put_out_data_ptr(&im_out);
00126 op.filter();
00127 }
00128
00129
00130 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00131 vil1_memory_image_of<double> mem(image);
00132 im_out = mem;
00133 vipl_dyadic<vil1_image,vil1_image,double,double> op(dif_double);
00134 op.put_in_data_ptr(&mem);
00135 op.put_out_data_ptr(&im_out);
00136 op.filter();
00137 }
00138
00139
00140 else {
00141 vcl_cerr << __FILE__ ": vepl1_dyadic_dif() not implemented for " << image << vcl_endl;
00142 }
00143 }
00144
00145 void vepl1_dyadic_min(vil1_image im_out, vil1_image const& image)
00146 {
00147
00148 if (vil1_pixel_format(image) == VIL1_BYTE) {
00149 vil1_memory_image_of<vxl_byte> mem(image);
00150 im_out = mem;
00151 vipl_dyadic<vil1_image,vil1_image,vxl_byte,vxl_byte> op(min_ubyte);
00152 op.put_in_data_ptr(&mem);
00153 op.put_out_data_ptr(&im_out);
00154 op.filter();
00155 }
00156
00157
00158 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00159 vil1_memory_image_of<vxl_uint_16> mem(image);
00160 im_out = mem;
00161 vipl_dyadic<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(min_ushort);
00162 op.put_in_data_ptr(&mem);
00163 op.put_out_data_ptr(&im_out);
00164 op.filter();
00165 }
00166
00167
00168 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00169 vil1_memory_image_of<float> mem(image);
00170 im_out = mem;
00171 vipl_dyadic<vil1_image,vil1_image,float,float> op(min_float);
00172 op.put_in_data_ptr(&mem);
00173 op.put_out_data_ptr(&im_out);
00174 op.filter();
00175 }
00176
00177
00178 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00179 vil1_memory_image_of<double> mem(image);
00180 im_out = mem;
00181 vipl_dyadic<vil1_image,vil1_image,double,double> op(min_double);
00182 op.put_in_data_ptr(&mem);
00183 op.put_out_data_ptr(&im_out);
00184 op.filter();
00185 }
00186
00187
00188 else {
00189 vcl_cerr << __FILE__ ": vepl1_dyadic_min() not implemented for " << image << vcl_endl;
00190 }
00191 }
00192
00193 void vepl1_dyadic_max(vil1_image im_out, vil1_image const& image)
00194 {
00195
00196 if (vil1_pixel_format(image) == VIL1_BYTE) {
00197 vil1_memory_image_of<vxl_byte> mem(image);
00198 im_out = mem;
00199 vipl_dyadic<vil1_image,vil1_image,vxl_byte,vxl_byte> op(max_ubyte);
00200 op.put_in_data_ptr(&mem);
00201 op.put_out_data_ptr(&im_out);
00202 op.filter();
00203 }
00204
00205
00206 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00207 vil1_memory_image_of<vxl_uint_16> mem(image);
00208 im_out = mem;
00209 vipl_dyadic<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(max_ushort);
00210 op.put_in_data_ptr(&mem);
00211 op.put_out_data_ptr(&im_out);
00212 op.filter();
00213 }
00214
00215
00216 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00217 vil1_memory_image_of<float> mem(image);
00218 im_out = mem;
00219 vipl_dyadic<vil1_image,vil1_image,float,float> op(max_float);
00220 op.put_in_data_ptr(&mem);
00221 op.put_out_data_ptr(&im_out);
00222 op.filter();
00223 }
00224
00225
00226 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00227 vil1_memory_image_of<double> mem(image);
00228 im_out = mem;
00229 vipl_dyadic<vil1_image,vil1_image,double,double> op(max_double);
00230 op.put_in_data_ptr(&mem);
00231 op.put_out_data_ptr(&im_out);
00232 op.filter();
00233 }
00234
00235
00236 else {
00237 vcl_cerr << __FILE__ ": vepl1_dyadic_max() not implemented for " << image << vcl_endl;
00238 }
00239 }
00240