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

Zooming.cpp

00001 /* Copyright (c) 2001 S.E. Grigorescu */
00002 
00003 #include "Zooming.h"
00004 
00005 template void Zoom< int >(Image< int >&, float, float, Image< int >&);
00006 template void Zoom< byte >(Image< byte >&, float, float, Image< byte >&);
00007 template void Zoom< float >(Image< float >&, float, float, Image< float >&);
00008 template void Zoom< int >(Image< int >&, float, Image< int >&);
00009 template void Zoom< byte >(Image< byte >&, float, Image< byte >&);
00010 template void Zoom< float >(Image< float >&, float, Image< float >&);
00011 template void Zoom< int >(Image< int >&, float, float);
00012 template void Zoom< byte >(Image< byte >&, float, float);
00013 template void Zoom< float >(Image< float >&, float, float);
00014 template void Zoom< int >(Image< int >&, float);
00015 template void Zoom< byte >(Image< byte >&, float);
00016 template void Zoom< float >(Image< float >&, float);
00017  
00018 template< class T > void Zoom(Image< T >& input, float xf, float yf, Image< T >& output)
00019 {
00020   Image< T > res((int)rint(xf*input.getWidth()), (int)rint(yf*input.getHeight()), 
00021                  output.getName());
00022   double alfa, beta;
00023   double xo, yo;
00024   int ir, jr;
00025 
00026   for (int i = 0; i < res.getHeight(); i++)
00027     for (int j = 0; j < res.getWidth(); j++){
00028       xo = ((double)j)/xf; yo = ((double)i)/yf;
00029       alfa = xo - floor(xo);
00030       beta = yo - floor(yo);
00031       jr = (int)floor(xo); ir = (int)floor(yo);
00032       if (jr >= 0 && jr < input.getWidth()-1 && ir >= 0 && ir < input.getHeight()-1)
00033         res[i][j] = (T)((1-alfa)*(1-beta)*input[ir][jr] + alfa*(1-beta)*input[ir][jr+1] + 
00034           (1-alfa)*beta*input[ir+1][jr] + alfa*beta*input[ir+1][jr+1]);      
00035       if (jr == -1 && jr < input.getWidth()-1 && ir >= 0 && ir < input.getHeight()-1)
00036         res[i][j] = (T)((1-beta)*input[ir][jr+1] + beta*input[ir+1][jr+1]);      
00037       if (jr >= 0 && jr == input.getWidth()-1 && ir >= 0 && ir < input.getHeight()-1)
00038         res[i][j] = (T)((1-beta)*input[ir][jr] + beta*input[ir+1][jr]);      
00039       if (jr >= 0 && jr < input.getWidth()-1 && ir == -1 && ir < input.getHeight()-1)
00040         res[i][j] = (T)((1-alfa)*input[ir+1][jr] + alfa*input[ir+1][jr+1]);      
00041       if (jr >= 0 && jr < input.getWidth()-1 && ir >= 0 && ir == input.getHeight()-1)
00042         res[i][j] = (T)((1-alfa)*input[ir][jr] + alfa*input[ir][jr+1]);
00043     }
00044   output = res;
00045 }
00046 
00047 template< class T > void Zoom(Image< T >& input, float xyf, Image< T >& output)
00048 {
00049   Zoom(input, xyf, xyf, output);
00050 }
00051 
00052 template< class T > void Zoom(Image< T >& input, float xf, float yf)
00053 {
00054   Zoom(input, xf, yf, input);
00055 }
00056 
00057 template< class T > void Zoom(Image< T >& input, float xyf)
00058 {
00059   Zoom(input, xyf, xyf, input);
00060 }
00061 
00062 
00063 
00064 
00065