Buscar en este blog

martes, 22 de mayo de 2007

ESCALA GEOMÉTRICA (Geometric Scaling)



Nombres comunes: Scale, Zoom, Shrink, Píxel Replication, Píxel Interpolation, Subsampling.

Puede ser usada para agrandar o reducir el tamaño de una imagen (o parte de una imagen). La reducción de una imagen es conocida generalmente como subsampling, y puede lograrse de dos maneras: una a través del remplazamiento (de los valores de un grupo de pixeles por un valor seleccionado arbitrariamente dentro de los valores de ese grupo) y la otra por interpolación (promediando los valores de intensidad de un grupo de pixeles para obtener el valor de intensidad de un píxel en la imagen reducida).

Este proceso no solo reduce el tamaño de los datos, sino también los efectos del ruido como sal y pimienta o el ruido gausiano.

Implementación en OpenCV

Resize
Resizes image
void cvResize( const CvArr* src, CvArr* dst, int interpolation=CV_INTER_LINEAR );
src
Source image.
dst
Destination image.
interpolation
Interpolation method:
· CV_INTER_NN - nearest-neigbor interpolation,
· CV_INTER_LINEAR - bilinear interpolation (used by default)
· CV_INTER_AREA - resampling using pixel area relation. It is preferred method for image decimation that gives moire-free results. In case of zooming it is similar to CV_INTER_NN method.
· CV_INTER_CUBIC - bicubic interpolation.
The function cvResize resizes image src so that it fits exactly to dst. If ROI is set, the function consideres the ROI as supported as usual.


CÓDIGO PARA REDUCIR EL TAMAÑO DE UNA IMAGEN

#include"highgui.h"
#include"cxcore.h"
#include"cv.h"
#include"cvaux.h"
#include"math.h"
#include"iostream.h"

void main(){
IplImage* img1 = cvLoadImage("../cam1.bmp", 1);
IplImage* img2 = cvLoadImage("../leg1.bmp", 1);

cvNamedWindow("Imagen Original (1)", 1);
cvShowImage("Imagen Original (1)", img1);

cvNamedWindow("Imagen Original (2)", 1);
cvShowImage("Imagen Original (2)", img2);

cvResize(img1, img2, CV_INTER_LINEAR);

cvNamedWindow("Imagen modificada", 1);
cvShowImage("Imagen modificada", img2);

cvWaitKey(0);
cvDestroyWindow("Imagen Original (1)");
cvDestroyWindow("Imagen Original (2)");
cvDestroyWindow("Imagen modificada");
}


En el código anterior se utilizaron dos imágenes de tamaños diferentes (cam1.bmp de 256x256 y leg1.bmp de 700x500) que son las siguientes:



cam1



leg1

No hay comentarios: