Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages   Examples  

Conversion.cpp

00001 /* Copyright (c) 2001 S.E. Grigorescu */
00002 
00003 #include "Conversion.h"
00004 
00005 void byte2int(Image< byte >& input, Image< int >& output)
00006 {
00007   Image< int > tmp_img(input.getWidth(), input.getHeight(), 
00008                        input.getName());
00009   for (int i = 0; i < input.getHeight(); i++)
00010     for (int j = 0; j < input.getWidth(); j++)
00011       tmp_img[i][j] = (int)input[i][j];
00012   output = tmp_img;
00013 }
00014 
00015 void byte2int(ByteImage& input, IntImage& output) 
00016 {
00017   IntImage tmp_img(input.getWidth(), input.getHeight(), 
00018                        input.getName());
00019   for (int i = 0; i < input.getHeight(); i++)
00020     for (int j = 0; j < input.getWidth(); j++)
00021       tmp_img[i][j] = (int)input[i][j];
00022   output = tmp_img;
00023 }
00024 
00025 void byte2float(Image< byte >& input, Image< float >& output) 
00026 {
00027   Image< float > tmp_img(input.getWidth(), input.getHeight(), 
00028                        input.getName());
00029   for (int i = 0; i < input.getHeight(); i++)
00030     for (int j = 0; j < input.getWidth(); j++)
00031       tmp_img[i][j] = (float)input[i][j];
00032   output = tmp_img;
00033 }
00034 
00035 void byte2float(ByteImage& input, FloatImage& output) 
00036 {
00037   FloatImage tmp_img(input.getWidth(), input.getHeight(), 
00038                        input.getName());
00039   for (int i = 0; i < input.getHeight(); i++)
00040     for (int j = 0; j < input.getWidth(); j++)
00041       tmp_img[i][j] = (float)input[i][j];
00042   output = tmp_img;
00043 }
00044 
00045 void int2byte(Image< int >& input, Image< byte >& output) 
00046 {
00047   Image< byte > tmp_img(input.getWidth(), input.getHeight(), 
00048                        input.getName());
00049   for (int i = 0; i < input.getHeight(); i++)
00050     for (int j = 0; j < input.getWidth(); j++)
00051       tmp_img[i][j] = input[i][j] == 0 ? 0 : 255;
00052   output = tmp_img;
00053 }
00054 
00055 void int2byte(IntImage& input, ByteImage& output) 
00056 {
00057   ByteImage tmp_img(input.getWidth(), input.getHeight(), 
00058                        input.getName());
00059   for (int i = 0; i < input.getHeight(); i++)
00060     for (int j = 0; j < input.getWidth(); j++)
00061       tmp_img[i][j] = input[i][j] == 0 ? 0 : 255;
00062   output = tmp_img;
00063 }
00064 
00065 void int2float(Image< int >& input, Image< float >& output) 
00066 {
00067   Image< float > tmp_img(input.getWidth(), input.getHeight(), 
00068                        input.getName());
00069   for (int i = 0; i < input.getHeight(); i++)
00070     for (int j = 0; j < input.getWidth(); j++)
00071       tmp_img[i][j] = (float)input[i][j];
00072   output = tmp_img;
00073 }
00074 
00075 void int2float(IntImage& input, FloatImage& output) 
00076 {
00077   FloatImage tmp_img(input.getWidth(), input.getHeight(), 
00078                        input.getName());
00079   for (int i = 0; i < input.getHeight(); i++)
00080     for (int j = 0; j < input.getWidth(); j++)
00081       tmp_img[i][j] = (float)input[i][j];
00082   output = tmp_img;
00083 }
00084 
00085 void float2byte(Image< float >& input, Image< byte >& output) 
00086 {
00087   Image< byte > tmp_img(input.getWidth(), input.getHeight(), 
00088                        input.getName());
00089   for (int i = 0; i < input.getHeight(); i++)
00090     for (int j = 0; j < input.getWidth(); j++)
00091       tmp_img[i][j] = fabs(input[i][j]) < 10e-6 ? 0 : 255;
00092   output = tmp_img;
00093 }
00094 
00095 void float2byte(FloatImage& input, ByteImage& output) 
00096 {
00097   ByteImage tmp_img(input.getWidth(), input.getHeight(), 
00098                        input.getName());
00099   for (int i = 0; i < input.getHeight(); i++)
00100     for (int j = 0; j < input.getWidth(); j++)
00101       tmp_img[i][j] = fabs(input[i][j]) < 10e-6 ? 0 : 255;
00102   output = tmp_img;
00103 }
00104 
00105 void float2int(Image< float >& input, Image< int >& output) 
00106 {
00107   Image< int > tmp_img(input.getWidth(), input.getHeight(), 
00108                        input.getName());
00109   for (int i = 0; i < input.getHeight(); i++)
00110     for (int j = 0; j < input.getWidth(); j++)
00111       tmp_img[i][j] = (int)rint(input[i][j]);
00112   output = tmp_img;
00113 }
00114 
00115 void float2int(FloatImage& input, IntImage& output) 
00116 {
00117   IntImage tmp_img(input.getWidth(), input.getHeight(), 
00118                        input.getName());
00119   for (int i = 0; i < input.getHeight(); i++)
00120     for (int j = 0; j < input.getWidth(); j++)
00121       tmp_img[i][j] = (int)rint(input[i][j]);
00122   output = tmp_img;
00123 }
00124 
00125 
00126 
00127 
00128 
00129 
00130