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;
y = fspecial('laplacian', 0.9);
d = fspecial('gaussian', [3 3], 500);
logs = fspecial('log', [3,3],0.5);
f = imfilter(x,y);
%fun = @(block_struct)block_struct.data;
r = imfilter(f,d);
logf = imfilter(r*4,logs);
%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
f1 = imresize(logf,0.5);
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);
rs4 = reshape(f1,size(f1,1)*size(f1,2),1);
%plot(x);
%hold on;
list = [rs1,rs4,rs3];
list = double(list);
clearvars rs1;
clearvars rs2;
clear rs3;
clearvars b;
clearvars c;
opts = statset('Display','final'); %other effects on k means
[km1,km2] = kmeans(list,3,'emptyaction', 'singleton','Replicate',5,'Options', opts); %kmeans
plot(list(km1 ==1,1), list(km1 ==1,2), 'r.', list(km1==2,1),list(km1==2,2),'b.',km2(:,1),km2(:,2),'kx'); %graph k-means
%have to resize km1 and km2, convert them to comparable size elements, and
%then imshow them.
k3= reshape(km1, 4351,3001);
k3 = imresize(k3,2);
imshow(k3);
No comments:
Post a Comment