Go to the documentation of this file.00001
00002 #include "vepl1_monadic.h"
00003 #include <vipl/accessors/vipl_accessors_vil1_image.h>
00004 #include <vipl/vipl_monadic.h>
00005 #include <vil1/vil1_memory_image_of.h>
00006 #include <vcl_cmath.h>
00007 #include <vcl_iostream.h>
00008 #include <vxl_config.h>
00009
00010 float abs_float(float const& a) { return (a<0) ? -a : a; }
00011 double abs_double(double const& a) { return vcl_fabs(a); }
00012 float sqrt_float(float const& a) { return (a<0) ? -vcl_sqrt(a) : vcl_sqrt(a); }
00013 double sqrt_double(double const& a) { return (a<0) ? -vcl_sqrt(a) : vcl_sqrt(a); }
00014 vxl_byte sqr_ubyte(vxl_byte const& a) { return vxl_byte(a*a); }
00015 vxl_uint_16 sqr_ushort(vxl_uint_16 const& a) { return vxl_uint_16(a*a); }
00016 float sqr_float(float const& a) { return a*a; }
00017 double sqr_double(double const& a) { return a*a; }
00018 static double shift_=0.0, scale_=1.0;
00019 vxl_byte shear_ubyte(vxl_byte const& a) { return vxl_byte((a+shift_)*scale_); }
00020 vxl_uint_16 shear_ushort(vxl_uint_16 const& a) { return vxl_uint_16((a+shift_)*scale_); }
00021 float shear_float(float const& a) { return float((a+shift_)*scale_); }
00022 double shear_double(double const& a) { return (a+shift_)*scale_; }
00023
00024
00025 vil1_image vepl1_monadic_abs(vil1_image const& image)
00026 {
00027
00028 if (vil1_pixel_format(image) == VIL1_BYTE) {
00029 return image;
00030 }
00031
00032
00033 else if (vil1_pixel_format(image) == VIL1_RGB_BYTE) {
00034 return image;
00035 }
00036
00037
00038 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00039 return image;
00040 }
00041
00042
00043 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00044 vil1_memory_image_of<float> mem(image);
00045 vil1_memory_image_of<float> out(image);
00046 vipl_monadic<vil1_image,vil1_image,float,float> op(abs_float);
00047 op.put_in_data_ptr(&mem);
00048 op.put_out_data_ptr(&out);
00049 op.filter();
00050 return out;
00051 }
00052
00053
00054 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00055 vil1_memory_image_of<double> mem(image);
00056 vil1_memory_image_of<double> out(image);
00057 vipl_monadic<vil1_image,vil1_image,double,double> op(abs_double);
00058 op.put_in_data_ptr(&mem);
00059 op.put_out_data_ptr(&out);
00060 op.filter();
00061 return out;
00062 }
00063
00064
00065 else {
00066 vcl_cerr << __FILE__ ": vepl1_monadic_abs() not implemented for " << image << vcl_endl;
00067 return 0;
00068 }
00069 }
00070
00071 vil1_image vepl1_monadic_sqrt(vil1_image const& image)
00072 {
00073
00074 if (vil1_pixel_format(image) == VIL1_FLOAT) {
00075 vil1_memory_image_of<float> mem(image);
00076 vil1_memory_image_of<float> out(image);
00077 vipl_monadic<vil1_image,vil1_image,float,float> op(sqrt_float);
00078 op.put_in_data_ptr(&mem);
00079 op.put_out_data_ptr(&out);
00080 op.filter();
00081 return out;
00082 }
00083
00084
00085 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00086 vil1_memory_image_of<double> mem(image);
00087 vil1_memory_image_of<double> out(image);
00088 vipl_monadic<vil1_image,vil1_image,double,double> op(sqrt_double);
00089 op.put_in_data_ptr(&mem);
00090 op.put_out_data_ptr(&out);
00091 op.filter();
00092 return out;
00093 }
00094
00095
00096 else {
00097 vcl_cerr << __FILE__ ": vepl1_monadic_sqrt() not implemented for " << image << vcl_endl;
00098 return 0;
00099 }
00100 }
00101
00102 vil1_image vepl1_monadic_sqr(vil1_image const& image)
00103 {
00104
00105 if (vil1_pixel_format(image) == VIL1_BYTE) {
00106 vil1_memory_image_of<vxl_byte> mem(image);
00107 vil1_memory_image_of<vxl_byte> out(image);
00108 vipl_monadic<vil1_image,vil1_image,vxl_byte,vxl_byte> op(sqr_ubyte);
00109 op.put_in_data_ptr(&mem);
00110 op.put_out_data_ptr(&out);
00111 op.filter();
00112 return out;
00113 }
00114
00115
00116 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00117 vil1_memory_image_of<vxl_uint_16> mem(image);
00118 vil1_memory_image_of<vxl_uint_16> out(image);
00119 vipl_monadic<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(sqr_ushort);
00120 op.put_in_data_ptr(&mem);
00121 op.put_out_data_ptr(&out);
00122 op.filter();
00123 return out;
00124 }
00125
00126
00127 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00128 vil1_memory_image_of<float> mem(image);
00129 vil1_memory_image_of<float> out(image);
00130 vipl_monadic<vil1_image,vil1_image,float,float> op(sqr_float);
00131 op.put_in_data_ptr(&mem);
00132 op.put_out_data_ptr(&out);
00133 op.filter();
00134 return out;
00135 }
00136
00137
00138 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00139 vil1_memory_image_of<double> mem(image);
00140 vil1_memory_image_of<double> out(image);
00141 vipl_monadic<vil1_image,vil1_image,double,double> op(sqr_double);
00142 op.put_in_data_ptr(&mem);
00143 op.put_out_data_ptr(&out);
00144 op.filter();
00145 return out;
00146 }
00147
00148
00149 else {
00150 vcl_cerr << __FILE__ ": vepl1_monadic_sqr() not implemented for " << image << vcl_endl;
00151 return 0;
00152 }
00153 }
00154
00155 vil1_image vepl1_monadic_shear(vil1_image const& image, double shift, double scale)
00156 {
00157 shift_ = shift; scale_ = scale;
00158
00159
00160 if (vil1_pixel_format(image) == VIL1_BYTE) {
00161 vil1_memory_image_of<vxl_byte> mem(image);
00162 vil1_memory_image_of<vxl_byte> out(image);
00163 vipl_monadic<vil1_image,vil1_image,vxl_byte,vxl_byte> op(shear_ubyte);
00164 op.put_in_data_ptr(&mem);
00165 op.put_out_data_ptr(&out);
00166 op.filter();
00167 return out;
00168 }
00169
00170
00171 else if (vil1_pixel_format(image) == VIL1_UINT16) {
00172 vil1_memory_image_of<vxl_uint_16> mem(image);
00173 vil1_memory_image_of<vxl_uint_16> out(image);
00174 vipl_monadic<vil1_image,vil1_image,vxl_uint_16,vxl_uint_16> op(shear_ushort);
00175 op.put_in_data_ptr(&mem);
00176 op.put_out_data_ptr(&out);
00177 op.filter();
00178 return out;
00179 }
00180
00181
00182 else if (vil1_pixel_format(image) == VIL1_FLOAT) {
00183 vil1_memory_image_of<float> mem(image);
00184 vil1_memory_image_of<float> out(image);
00185 vipl_monadic<vil1_image,vil1_image,float,float> op(shear_float);
00186 op.put_in_data_ptr(&mem);
00187 op.put_out_data_ptr(&out);
00188 op.filter();
00189 return out;
00190 }
00191
00192
00193 else if (vil1_pixel_format(image) == VIL1_DOUBLE) {
00194 vil1_memory_image_of<double> mem(image);
00195 vil1_memory_image_of<double> out(image);
00196 vipl_monadic<vil1_image,vil1_image,double,double> op(shear_double);
00197 op.put_in_data_ptr(&mem);
00198 op.put_out_data_ptr(&out);
00199 op.filter();
00200 return out;
00201 }
00202
00203
00204 else {
00205 vcl_cerr << __FILE__ ": vepl1_monadic_shear() not implemented for " << image << vcl_endl;
00206 return 0;
00207 }
00208 }
00209