Você está na página 1de 11

INSTITUTO TECNOLÓGICO Y DE ESTUDIOS SUPERIORES DE MONTERREY

SISTEMAS DE VISION POR COMPUTADORA


JUAN BARRIOS AVILÉS
887586
EJERCICIOS OPENCV

Ejercicio 5.2
Smooth

Imagen original

#include "cv.h"
#include "highgui.h"

void example2_4( IplImage* image )


{
// Create some windows to show the input
// and output images in.
//
cvNamedWindow( "Example2_4-in", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "Example2_4-out", CV_WINDOW_AUTOSIZE );

// Create a window to show our input image


//
cvShowImage( "Example2_4-in", image );

// Create an image to hold the smoothed output


//
IplImage* out = cvCreateImage(
cvGetSize(image),
IPL_DEPTH_8U,
3
);

// Do the smoothing
//
cvSmooth( image, out, CV_GAUSSIAN, 5,5 );
cvSmooth( out, out, CV_GAUSSIAN, 5, 5);
// Show the smoothed image in the output window
//
cvShowImage( "Example2_4-out", out );

// Be tidy
//
cvReleaseImage( &out );

// Wait for the user to hit a key, then clean up the windows
//
cvWaitKey( 0 );
cvDestroyWindow("Example2_4-in" );
cvDestroyWindow("Example2_4-out" );

int main( int argc, char** argv )


{
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img );
example2_4( img );
// cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow("Example1");
}

Smoothing Gaussian 5X5

a. ¿Qué encontraste?
Se observa un efecto de partición de partículas, de manera tal como un desenfoque.
Smooth Gaussian 9X9

b. ¿Qué encontraste?
Se observa al igual que la imagen de 5X5 como el punto se esparce dentro de la imagen
similar a la expansion de particulas

Smooth Gaussian 5X5 dos veces VS Smooth Gaussian 9X9

VS

c. ¿Son las imágenes parecidas?, ¿por qué y por qué no?


Debido a la dimensión del punto que se puso en la imagen es complicado encontrar una
diferencia sin embargo en teoría el smooth gaussian de 5X5 doble debe presentar un
mayor desenfoque debido a que se hace en dos tiempos diferentes y a dos imágenes
diferentes.
Ejercicio 5.12
 Imagen original

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

void sum_rgb( IplImage* src, IplImage* dst ) {


// Allocate individual image planes.
IplImage* r = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
IplImage* g = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
IplImage* b = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );

// Temporary storage.
IplImage* s = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );

// Split image onto the color planes.


cvSplit( src, r, g, b, NULL );

// Add equally weighted rgb values.


cvAddWeighted( r, 1./3., g, 1./3., 0.0, s );
cvAddWeighted( s, 2./3., b, 1./3., 0.0, s );

// Truncate values above 100.


cvThreshold( s, dst, 128, 128, CV_THRESH_TOZERO ); //La zona amarilla indica en donde es
necesario hacer los cambios para obtener las diferentes imagenes

cvReleaseImage( &r );
cvReleaseImage( &g );
cvReleaseImage( &b );
cvReleaseImage( &s );
}

int main(int argc, char** argv)


{

// Create a named window with a the name of the file.


cvNamedWindow( argv[1], 1 );

// Load the image from the given file name.


IplImage* src = cvLoadImage( argv[1] );
IplImage* dst = cvCreateImage( cvGetSize(src), src->depth, 1);
sum_rgb( src, dst);

// Show the image in the named window


cvShowImage( argv[1], dst );

// Idle until the user hits the "Esc" key.


while( 1 ) { if( (cvWaitKey( 10 )&0x7f) == 27 ) break; }

// Clean up and don’t be piggies


cvDestroyWindow( argv[1] );
cvReleaseImage( &src );
cvReleaseImage( &dst );

}
 Primeramente se pide familiarizar con conceptos del threshold que maneja el OPENCV
CV_THRESHOLD_BINARY
CV_THRESHOLD_BINARY_INV

CV_THRESHOLD_TRUNC
CV_THRESHOLD_TOZERO_INV

CV_THRESHOLD_TOZERO
ADAPTIVE THRESHOLDS

#include <stdio.h>
#include <cv.h>
#include <highgui.h>
void sum_rgb( IplImage* src, IplImage* dst ) {
// Allocate individual image planes.
IplImage* r = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
IplImage* g = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
IplImage* b = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
// Split image onto the color planes.
cvSplit( src, r, g, b, NULL );
// Temporary storage.
IplImage* s = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
// Add equally weighted rgb values.
cvAddWeighted( r, 1./3., g, 1./3., 0.0, s );
cvAddWeighted( s, 2./3., b, 1./3., 0.0, s );
// Truncate values above 100.

//cvThreshold( s, dst, 100, 100, CV_THRESH_TRUNC );


cvAdaptiveThreshold(s, dst, 255, CV_ADAPTIVE_THRESH_MEAN_C,
CV_THRESH_BINARY_INV, 3, -5); Lo que esta en amarillo muestra los parámetros que
fueron necesarios cambiar para lograr las imágenes que se pedían en la practica

cvReleaseImage( &r );
cvReleaseImage( &g );
cvReleaseImage( &b );
cvReleaseImage( &s );
}
int main(int argc, char** argv)
{
// Create a named window with the name of the file.
cvNamedWindow( argv[1], 1 );
// Load the image from the given file name.
IplImage* src = cvLoadImage( argv[1] );
IplImage* dst = cvCreateImage( cvGetSize(src), src->depth, 1);
sum_rgb( src, dst);
// Show the image in the named window
cvShowImage( argv[1], dst );
// Idle until the user hits the “Esc” key.
while( 1 ) { if( (cvWaitKey( 10 )&0x7f) == 27 ) break; }
// Clean up and don’t be piggies
cvDestroyWindow( argv[1] );
cvReleaseImage( &src );
cvReleaseImage( &dst );
}
ADAPTIVE THRESHOLD PARAM1=5 THRESHOLD BINARY

ADAPTIVE THRESHOLD PARAM1=5 THRESHOLD BINARY INV


ADAPTIVE THRESHOLD PARAM1=0 THRESHOLD BINARY

ADAPTIVE THRESHOLD PARAM1=0 THRESHOLD BINARY INV


ADAPTIVE THRESHOLD PARAM1=-5 THRESHOLD BINARY

ADAPTIVE THRESHOLD PARAM1=-5 THRESHOLD BINARY INV

Você também pode gostar