% ========================================================================= % Math 336 - Image Processing - Laboratory 6 % % Image Morphology (Part 2): % Use morphological operations to filter the images of the cells. % % Marty Kandes % Computational Science Research Center / Department of Physics % San Diego State University % Fall 2008 % ------------------------------------------------------------------------- clear all; close all; clc; % Clear Matlab workspace. F = imread('normal.tiff'); % Read in the image of normal cells G = imread('cancer.tiff'); % Read in the image of cancer cells. imwrite(F,'normalrgb.jpg','jpg'); % Write color images to jpg files. imwrite(G,'cancerrgb.jpg','jpg'); % F = rgb2gray(F); % Convert normal image to grayscale. G = rgb2gray(G); % Convert cancer image to grayscale. figure; % Open new figure. imshow(F); % Display normal cell grayscale image. imwrite(F,'normalgray.jpg','jpg'); % Write normal cell grayscale image to file. figure; % Open new figure. imshow(G); % Display cancerous cell binary image. imwrite(G,'cancergray.jpg','jpg'); % Write cancerous cell binary image to file. F = im2bw(F,graythresh(F)); % Convert grayscale normal to binary image. G = im2bw(G,graythresh(G)); % Convert grayscale cancer to binary image. F = ~F; % Invert binary image of normal cells. G = ~G; % Invert binary image of cancerous cells. figure; % Open new figure. imshow(F); % Display normal cell binary image. imwrite(F,'normalbinary.jpg','jpg'); % Write normal cell binary image to file. figure; % Open new figure. imshow(G); % Display cancerous cell binary image. imwrite(G,'cancerbinary.jpg','jpg'); % Write cancerous cell binary image to file. M = 5; N = 5; % Set dimensions of the structure element. SE = ones(M,N); % Build square structure element. AP = [3,3]; % Set active point of the SE. H = mfilter(F,SE,AP,'binary','close'); % Apply morphological filter. H = mfilter(H,SE,AP,'binary','open'); % Apply morphological filter. figure; % Open new figure. imshow(H); % Display filtered binary image. imwrite(H,'normalbinaryfiltered.jpg','jpg'); % Write filtered binary image to file. M = 3; N = 3; % Set dimensions of the structure element. SE = ones(M,N); % Build square structure element. AP = [2,2]; % Set active point of the SE. I = mfilter(G,SE,AP,'binary','close'); % Apply morphological filter. I = mfilter(I,SE,AP,'binary','open'); % Apply morphological filter. figure; % Open new figure. imshow(I); % Display filtered binary image. imwrite(I,'cancerbinaryfiltered.jpg','jpg'); % Write filtered binary image to file. M = 3; N = 3; % Set dimensions of the structure element. SE = ones(M,N); % Build square structure element. AP = [2,2]; % Set active point of the SE. H = H - merode(H,SE,AP,'binary'); % Compute boundary extraction; I = I - merode(I,SE,AP,'binary'); % figure; % imshow(H); % figure; % imshow(I); % imwrite(H,'normalbinarybound.jpg','jpg'); % Write boundary image to file. imwrite(I,'cancerbinarybound.jpg','jpg'); % Write boundary image to file. F = imread('normal.tiff'); % Read in the image of normal cells G = imread('cancer.tiff'); % Read in the image of cancer cells. F = rgb2gray(F); % Convert normal image to grayscale. G = rgb2gray(G); % Convert cancer image to grayscale. F = edge(F,'sobel'); % Apply sobel filter. G = edge(G,'sobel'); % Apply sobel filter. imwrite(F,'normalsobel.jpg','jpg'); % Write sobel image to file. imwrite(G,'cancersobel.jpg','jpg'); % Write sobel image to file. % =========================================================================