Image segmentation using NN .. what is my mistake in the following code?
Afficher commentaires plus anciens
I do image segmentation as preprocessing step to finding similarity.
Calculate similarity between 2 images as follow:
- image resize.
- image segmentation using clustering (SOM and LVQ) for the 2 images.
- find similarity level using the like_som function.
clear;
fix = imread('cameraman.tif');
len = size(fix(:));
small_img = imresize(fix,[50 50]);
hist_learn = imhist(small_img);
% replicate image hist to feed NN.
hist_learn = [hist_learn hist_learn];
%%SOM and LVQ network
net_v = selforgmap([10,10]);
net_v = train(net_v,hist_learn);
c = net_v(hist_learn); %class
n = lvqnet(10);
n = train(n,hist_learn,c);
%%Compare the org. image with (same) image after transformation
% Try to calc. similarity using NN.
min = -100;
max = 100;
Rout = imref2d(size(fix)); %create Reference2D object
out = zeros(21,11);
i=1;
for shift_x = min:10:max
cfloat = fix;
t=[1 0 0;0 1 0;shift_x 0 1];
tform = affine2d(t);
cfloat = imwarp(cfloat,tform,'outputView',Rout,'FillValues',cfloat(1,1));
small_img = imresize(cfloat,[50 50]);
%Calc. similarity between 2 images
out(i,:) = like_som(small_img,hist_learn,n);
i = i +1;
end
the like_som function
function out = like_som(im, hist, net)
hs = imhist(im);
cls = vec2ind(net(hs));
out = zeros(1,11);
[~, n] = size(hist);
for i = 1 : n
hist_i = hist(:, i);
n_hist = net(hist_i);
org_cls = vec2ind(n_hist);
if(cls == org_cls )
out(i) =1;
figure;imshow(im);title(['float, i = ' num2str(i)]);
end
end
% figure;imshow(im);title('float');
end
Réponses (0)
Catégories
En savoir plus sur Deep Learning for Image Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!