Ejemplos DE Programas DE PDI PDF

Title Ejemplos DE Programas DE PDI
Author jose ramirez
Course Automatizacion y Control de Procesos Industriales Turno 01t Ciclo 8
Institution Universidad Nacional del Callao
Pages 8
File Size 92.8 KB
File Type PDF
Total Downloads 69
Total Views 134

Summary

procesamiento de imagenes...


Description

EJEMPLOS DE PROGRAMAS DE PDI (PDSA – 7-11-2020) 1.

Calcula la diferencia absoluta entre dos imágenes %% Display Absolute Difference between Filtered image and Original % %% % Read image into workspace. % Copyright 2015 The MathWorks, Inc. I = imread('cameraman.tif'); %% % Filter the image. J = uint8(filter2(fspecial('gaussian'), I)); %% % Calculate the absolute difference of the two images. K = imabsdiff(I,J); %% % Display the absolute difference image. figure imshow(K,[])

2. Detecta bordes en Imágenes %% Detect Edges in Images % This example shows how to detect edges in an image using both the Canny % edge detector and the Sobel edge detector. %% % Read image and display it. % Copyright 2015 The MathWorks, Inc. I = imread('coins.png'); imshow(I) %% % Apply both the Sobel and Canny edge detectors to the image and display % them for comparison. BW1 = edge(I,'sobel'); BW2 = edge(I,'canny'); figure; imshowpair(BW1,BW2,'montage') title('Sobel Filter Canny Filter');

3. Agregar ruido a una imagen %% Add noise to an image. % Add noise to an image. %% % Copyright 2015 The MathWorks, Inc. I = imread('eight.tif'); J = imnoise(I,'salt & pepper',0.02); figure, imshow(I) figure, imshow(J)

4. Calcular un Histograma %% Calculate Histogram % %% % Copyright 2015 The MathWorks, Inc. I = imread('pout.tif'); imhist(I)

5. Ajustar el Contraste de una Imagen Gris %% Adjust Contrast of Grayscale Image % %% % Read a low-contrast grayscale image into the workspace and display it. % Copyright 2015 The MathWorks, Inc. I = imread('pout.tif'); imshow(I); %% % Adjust the contrast of the image so that 1% of the data is saturated at % low and high intensities, and display it. J = imadjust(I); figure imshow(J)

6. Ajustar el contraste de una imagen RGB %% Adjust Contrast of RGB Image % %% % Read an RGB image into the workspace and display it. % Copyright 2015 The MathWorks, Inc. RGB = imread('football.jpg'); imshow(RGB) %% % Adjust the contrast of the RGB image, specifying contrast limits. RGB2 = imadjust(RGB,[.2 .3 0; .6 .7 1],[]); figure imshow(RGB2)

7. Aplicar filtro personalizado a la región de interés en la imagen %% Apply Custom Filter to Region of Interest in Image % This example shows how to filter a region of interest (ROI), using the % |roifilt2| function to specify the filter. |roifilt2| enables you to % specify your own function to operate on the ROI. This example uses the % |imadjust| function to lighten parts of an image. %% % Read an image into the workspace and display it. % Copyright 2015 The MathWorks, Inc. I = imread('cameraman.tif'); figure imshow(I) %% % Create the mask image. This example uses a binary image of text as the % mask image. All the 1-valued pixels define the regions of interest. The % example crops the image because a mask image must be the same size as the % image to be filtered. BW = imread('text.png'); mask = BW(1:256,1:256); figure imshow(mask) %%

% Create the function you want to use as a filter. f = @(x) imadjust(x,[],[],0.3); %% % Filter the ROI, specifying the image to be filtered, the mask that % defines the ROI, and the filter that you want to use. I2 = roifilt2(I,mask,f); %% % Display the result. figure imshow(I2)

8. Aplicar filtro personalizado a la región de interés en la imagen: utilizar filtrado enmascarado para aumentar el contraste %% Apply Filter to Region of Interest in an Image % This example shows how to use masked filtering to increase the contrast % of a specific region of an image. %% % Read a grayscale image into the workspace. % Copyright 2015 The MathWorks, Inc. I = imread('pout.tif'); figure h_img = imshow(I); %% % Draw an ellipse over the image to specify the region of interest, using % the |imellipse| function. The coordinates used to specify the size of % the ellipse have been predetermined. imellipse returns an |imellipse| % object. e = imellipse(gca,[55 10 120 120]); %% % Create the mask. Use the |createMask| method of the |imellipse| object. mask = createMask(e,h_img); %% % Create the filter using the |fspecial| function. h = fspecial('unsharp'); %% % Apply the filter to the specified region of interest, using |roifilt2| . I2 = roifilt2(h,I,mask); %% % Display the result. figure imshow(I2)

9. Aplicar filtros de suavizado gaussiano a las imágenes %% Apply Gaussian Smoothing Filters to Images % This example shows how to apply different Gaussian smoothing filters to % images using |imgaussfilt|. Gaussian smoothing filters are commonly used % to reduce noise. %% % Read an image into the workspace. % Copyright 2015 The MathWorks, Inc. I = imread('cameraman.tif'); %% % Filter the image with isotropic Gaussian smoothing kernels of increasing % standard deviations. Gaussian filters are generally isotropic, that is, % they have the same standard deviation along both dimensions. An image can % be filtered by an isotropic Gaussian filter by specifying a scalar value % for |sigma|. Iblur1 = imgaussfilt(I,2); Iblur2 = imgaussfilt(I,4); Iblur3 = imgaussfilt(I,8); %% % Display the original image and all the filtered images. figure imshow(I) title('Original image') figure imshow(Iblur1) title('Smoothed image, \sigma = 2') figure imshow(Iblur2) title('Smoothed image, \sigma = 4') figure imshow(Iblur3) title('Smoothed image, \sigma = 8') %% % Filter the image with anisotropic Gaussian smoothing kernels. % |imgaussfilt| allows the Gaussian kernel to have different standard % deviations along row and column dimensions. These are called axis-aligned % anisotropic Gaussian filters. Specify a 2-element vector for |sigma| when

% using anisotropic filters. IblurX1 = imgaussfilt(I,[4 1]); IblurX2 = imgaussfilt(I,[8 1]); IblurY1 = imgaussfilt(I,[1 4]); IblurY2 = imgaussfilt(I,[1 8]); %% % Display the filtered images. figure imshow(IblurX1) title('Smoothed image, \sigma_x = 4, \sigma_y = 1') figure imshow(IblurX2) title('Smoothed image, \sigma_x = 8, \sigma_y = 1') figure imshow(IblurY1) title('Smoothed image, \sigma_x = 1, \sigma_y = 4') figure imshow(IblurY2) title('Smoothed image, \sigma_x = 1, \sigma_y = 8') %% % Suppress the horizontal bands visible in the sky region of the original % image. Anisotropic Gaussian filters can suppress horizontal or vertical % features in an image. Extract a section of the sky region of the image % and use a Gaussian filter with higher standard deviation along the X % axis (direction of increasing columns). I_sky = imadjust(I(20:50,10:70)); IblurX1_sky = imadjust(IblurX1(20:50,10:70)); %% % Display the original patch of sky with the filtered version. figure imshow(I_sky), title('Sky in original image') figure imshow(IblurX1_sky), title('Sky in filtered image')

10.

Aplicar un filtro Gabor único a la imagen de entrada

%% Apply Single Gabor Filter to Input Image % %% % Read image into the workspace. % Copyright 2015 The MathWorks, Inc. I = imread('board.tif'); %% % Convert image to grayscale. I = rgb2gray(I); %% % Apply Gabor filter to image. wavelength = 4; orientation = 90; [mag,phase] = imgaborfilt(I,wavelength,orientation); %% % Display original image with plots of the magnitude and phase calculated % by the Gabor filter. figure subplot(1,3,1); imshow(I); title('Original Image'); subplot(1,3,2); imshow(mag,[]) title('Gabor magnitude'); subplot(1,3,3); imshow(phase,[]); title('Gabor phase');

11.

Calcular el número de Euler para la imagen binaria

%% Calculate Euler Number for Binary Image % %% % Read binary image into workspace, and display it. % Copyright 2015 The MathWorks, Inc. BW = imread('circles.png'); imshow(BW) %% % Calculate the Euler number. In this example, all the circles touch so % they create one object. The object contains four "holes", which are the % black areas created by the touching circles. Thus the Euler number is 1 % minus 4, or -3. bweuler(BW)

12. Calcular los pesos de diferencia de intensidad de escala de grises %% Calculate Grayscale Intensity Difference Weights % This example segments an object in an image using Fast Marching Method % using grayscale intensity difference weights calculated from the % intensity values at the seed locations. %% % Read image and display it. % Copyright 2015 The MathWorks, Inc. I = imread('cameraman.tif'); imshow(I) title('Original Image') %% % Specify row and column index of pixels for use a reference grayscale % intensity value. seedpointR = 159; seedpointC = 67; %% % Calculate the grayscale intensity difference weight array for the image % and display it. The example does log-scaling of |W| for better % visualization. W = graydiffweight(I, seedpointC, seedpointR,'GrayDifferenceCutoff',25); figure, imshow(log(W),[]) %% % Segment the image using the grayscale intensity difference weight array. % Specify the same seed point vectors you used to create the weight array. thresh = 0.01; BW = imsegfmm(W, seedpointC, seedpointR, thresh); figure, imshow(BW) title('Segmented Image')

Jorge A. Del Carpio Salinas Mail: [email protected]...


Similar Free PDFs