You are on page 1of 6

Juei-Sheng Chiu - Module

4, Computational Methods
(EGRB 215) 4/26/15

Table of Contents
Clean Up .......................................................................................................................... 1
Honor Statement ................................................................................................................ 1
Problem 1 ......................................................................................................................... 1
Problem 2 - use function to process image .............................................................................. 5

Clean Up
clear all
close all
clc

Honor Statement
On my honor, I have neither given nor received aid on this assignment, and I pledge that I am in compliance
with the VCU Honor System

% signed Joshua Chiu


% Date: 4/26/2015

Problem 1
[at3 map3] = imread('AT3_1m4_01.tif');
ed1sobel = edge(at3, 'sobel');
ed1canny = edge(at3, 'canny');
figure(1)
subplot(1, 2, 1)
imshow(ed1sobel, map3); title('Edge using Sobel');
subplot(1, 2, 2)
imshow(ed1canny, map3); title('Edge using Canny');

% I think that the Sobel method had a better edge detection result. Canny
% can be better at detecting weak edges, but in this case the boundaries of
% the cells are relatively distinct, and canny ends up detecting the
% 'noise' that we don't want to detect. Therefore, Sobel is a better fit
% because of the high level of noise in the image.

% c Testing different thresholds

1
Juei-Sheng Chiu - Module 4, Compu-
tational Methods (EGRB 215) 4/26/15

figure(2)
n = 0;
for i = .02:.03:.11
n = n + 1;
ed1t = edge(at3, 'sobel', i);
subplot(1, 4, n);
imshow(ed1t); title(num2str(i));
end
figure(3)
n = 0;
for i = .14:.03:.2
n = n + 1;
ed1t = edge(at3, 'sobel', i);
subplot(1, 4, n);
imshow(ed1t); title(num2str(i));
end
at3 = edge(at3, 'sobel');
subplot(1, 4, 4);
imshow(ed1t); title('Matlab-set');
% I think the best value for threshold is .11; however allowing matlab to
% create it gives an even better result based on the amount of noise and
% the ease of manipulating the data later.

%d morpholgical operations

se = strel('disk', 4);
at3 = imclose(at3, se);
at3 = imopen(at3, se);
at3 = imfill(at3, 'holes');

at3 = imerode(at3, se);

at3 = imerode(at3, se);


at3 = imopen(at3, se);
se = strel('disk', 6);
at3 = imdilate(at3, se);

% e imclearborder
%at3 = imclearborder(at3); % Running imclearborder negatively impacts
%results, so it isn't used.

% f bwaeaopen
at3 = bwareaopen(at3, 1);
figure(4);
imshow(at3)

% g, h get bounding box and area of target objects


stats = regionprops(at3, 'area', 'boundingbox');
for i = 1:length(stats)
rectangle('Position', stats(i).BoundingBox, 'EdgeColor', 'b')
disp(['The area of object #' num2str(i) ' is ' num2str(stats(i).Area)]);

temp = imcrop(at3, stats(i).BoundingBox);


filename = sprintf('mat_img_%d.tif', i) ;

2
Juei-Sheng Chiu - Module 4, Compu-
tational Methods (EGRB 215) 4/26/15

imwrite(temp, filename, 'tif') ;

end

The area of object #1 is 2059

The area of object #2 is 3014


The area of object #3 is 1874
The area of object #4 is 1809
The area of object #5 is 1241
The area of object #6 is 2400
The area of object #7 is 1868
The area of object #8 is 1468

3
Juei-Sheng Chiu - Module 4, Compu-
tational Methods (EGRB 215) 4/26/15

4
Juei-Sheng Chiu - Module 4, Compu-
tational Methods (EGRB 215) 4/26/15

Problem 2 - use function to process image


out =joshchiusproprietaryimageprocessingsoftware(imread('AT3_1m4_10.tif'));
stats = regionprops(out, 'area', 'boundingbox');
figure(5);
imshow(out)

for i = 1:length(stats)
rectangle('Position', stats(i).BoundingBox, 'EdgeColor', 'g')
disp(['The area of object #' num2str(i) ' is ' num2str(stats(i).Area)]);
end

type joshchiusproprietaryimageprocessingsoftware

The area of object #1 is 2697


The area of object #2 is 2836
The area of object #3 is 963
The area of object #4 is 1917
The area of object #5 is 1692
The area of object #6 is 1778
The area of object #7 is 1718
The area of object #8 is 981

function [BW] = joshchiusproprietaryimageprocessingsoftware(I)


%UNTITLED Summary of this function goes here
% accepts as input an image, I; performs the same operations (steps b-f)
% as the script, using the optimized values returns a logical array, BW

5
Juei-Sheng Chiu - Module 4, Compu-
tational Methods (EGRB 215) 4/26/15

% Edge - sobel function


I = edge(I, 'sobel');
% Use matlab threshold, which was determined to be of superior function.

se = strel('disk', 4);
I = imclose(I, se);
I = imopen(I, se);
I = imfill(I, 'holes');
I = imerode(I, se);
I = imerode(I, se);
I = imopen(I, se);
se = strel('disk', 6);
I = imerode(I, se);
I = imdilate(I, se);
I = imdilate(I, se);
I = bwareaopen(I, 1);
BW = I;
end

Published with MATLAB® 7.12

You might also like