Read the corresponding image in matlab

I calculated the distance between an image A1 and different images like image1,image2,image3 and image4 based on its hierarchicalCentroid. dist_1_1{ii} contains 4 values. I want to find the minimum value present in the dist_1_1{ii}.But I shows the value 1 and also i want to show the image which gives minimum value. Please help me. Thanks in advance
%%demo
clc,clear all,close all
plotFlag = 1;
depth = 6;
alef1 = im2bw(imread('C1.bmp')); %%Binary image
vec1 = hierarchicalCentroid(alef1,depth,plotFlag);
% subplot(1,3,1);
A=[];
vec2=[];
dist_1_1=[];
for ii=1:4
A{ii} = imread(['image' num2str(ii) '.bmp']);
% subplot(1,3,2);
vec2{ii} = hierarchicalCentroid(A{ii},depth,plotFlag);
%subplot(1,3,3);
%vec3 = hierarchicalCentroid(tav,depth,plotFlag);
% vec4=hierarchicalCentroid(A,depth,plotFlag);
% vec5=hierarchicalCentroid(A,depth,plotFlag);
dist_1_1{ii} = sum((vec1 - vec2{ii}) .^ 2);
[~,I] = min(dist_1_1{ii});
figure;
subplot(1,2,1);imshow(alef1);
subplot(1,2,2);imshow(A{I});
end

7 comentarios

Image Analyst
Image Analyst el 24 de Jul. de 2015
What is ind? And what does the function dist() do? It looks like it some how produces a single number. But if it's a single number, then how can there be a min, like when you say " the minimum distance from A1 and A". I thought that was 0.76 so there's just a single number, no min, no max, and no other numbers. And I don't know what "corresponding" means here. Corresponding to what ? To each distance? To the min distance (whatever that is)? Please clarify.
annmaria
annmaria el 25 de Jul. de 2015
Sir I changed my question and I added some codes.I want the variable I have the smallest value present in the dist_1_1{ii}.But it shows the value one(1). So A{I} shows the first image present in the folder. dist_1_1{ii} have the values 1.9009,1.6763,0.3698,1.1932
If you want I to have the smallest value present in dist_1_1{ii} then you should be using
I = min(dist_1_1{ii});
Your current code of
[~,I] = min(dist_1_1{ii});
is for setting I to be the index of the smallest value; that is, dist_1_1{ii}(I) would contain the smallest value.
annmaria
annmaria el 25 de Jul. de 2015
Sir I tried it.But actually the variable I gives the last value.It does not give the minimum value.
Thankyou for your guidance. I found out the minimum using
MinVal=min(cell2mat(dist_1_1)); Now I want to find the corresponding image. MinVal give the minimum value
imshow(A(MinVal)) does not give the corresponding image.How will i get it?what are changes need to be done to get this? Please help me –
[~,I] = min(dist_1_1{ii});
imshow(A{I})
annmaria
annmaria el 26 de Jul. de 2015
thank you sir Its working

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Jul. de 2015

0 votos

You have a variable "m" that tells you which is the image with the minimum distance, but you have not indicated anything about how "m" corresponds to a file name. Are the file names sequential such as img1.tif img2.tif img3.tif ... img9.tif img10.tif img11.tif ? Did you use dir() to find the names of the images and you still have the result of dir() stored?

Más respuestas (0)

Etiquetas

Preguntada:

el 24 de Jul. de 2015

Comentada:

el 26 de Jul. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by