Friday, May 17, 2013

5/17/2013 K-Means continued

clc
close all
clear all

i = imread('Image1.tif');

j = i(:, :, 1:3);
red = i(:,:,1);
clearvars i;
x = rgb2gray(j);
grad = edge(x, 'canny');
gradient = grad;
clearvars grad;
y = fspecial('laplacian', 0.9);
d = fspecial('gaussian', [3 3], 500);
f = imfilter(x,y);

%fun = @(block_struct)block_struct.data;


r = imfilter(f,d);
%figure, imshow(r*4);
clearvars f;
clearvars y;
clearvars d;
clearvars j;
clearvars grad;
b = imresize(4*r,0.5); %numbers for the filtered image
c = imresize(gradient,0.5); %numbers for gradient.
e = imresize(red,0.5); %color red resized

rs1 = reshape(b,size(b,1)*size(b,2),1); %creates an m by n matrix of size
rs2 = reshape(c, size(c,1)*size(c,2),1); %creates an m by n matrix of the edge
rs2 = uint8(rs2);
rs3 = reshape(e,size(e,1)*size(e,2),1);
res3 = uint8(rs3);

plot(x);
hold on;

list = [rs1,rs3];
list = double(list);
clearvars rs1;
clearvars rs2;
clear rs3;
clearvars b;
clearvars c;
opts = statset('Display','final');
[km1,km2] = kmeans(list,2,'emptyaction', 'singleton','Replicate',5,'Options', opts);
plot(list(km1 ==1,1), list(km1 ==1,2), 'r.', list(km1==2,1),list(km1==2,2),'b.',km2(:,1),km2(:,2),'kx');

No comments:

Post a Comment