Compare each image with another
Mostrar comentarios más antiguos
As suggested by @Image Analyst to read images from the system to workspace I am using his code he answered on a different question.
folder = 'D:\My Pictures\whatever'
filePattern = fullfile(folder, '*.jpg');
f=dir(filePattern)
files={f.name}
for k=1:numel(files)
fullFileName = fullfile(folder, files{k})
cellArrayOfImages{k}=imread(fullFileName)
end
Now I want to compare each image in my workspace to other image using the score ssim(). I have to categorize those images into 4 groups dependent on the score (0.7,0.9) using ifelse and also then save them into different folders in my system which would be great. Please let me know how can I do this which would also not slow the system as I have lots of images. Thanks in advance.
2 comentarios
KALYAN ACHARJYA
el 2 de Jul. de 2019
@Abhishake Suppose you have called the image1,
Now, you have to find SSIM in between image1 and ??? Please clarify?
group1={};group2={}...... %Preallocation
n=1,m=1.....
if SSIM_value==0.7
group1{n}=current_image
n=n+1;
elseif
...
So on....
Abhishek Singh
el 2 de Jul. de 2019
Respuesta aceptada
Más respuestas (1)
Anu
el 16 de En. de 2022
0 votos
folder = 'C:\Users\anusu\Downloads\figures\New folder';
filePattern = fullfile(folder, '*.tif');
f=dir(filePattern);
files={f.name};
numImages = numel(files);
allSsim = ones(numImages, numImages);
for k = 1 : numImages - 1
fullFileName1 = fullfile(folder, files{k});
image1 = imread(fullFileName1);
for k2 = k + 1 : numImages
fullFileName2 = fullfile(folder, files{k2});
image2 = imread(fullFileName2);
[ssimval,ssimmap] = ssim(image1,image2);
figure();
imshow(ssimmap,[])
title('Local SSIM Map with Global SSIM Value:'+num2str(ssimval))
subtitle(sprintf('%d',k, k2))
fileC = fullfile(folder, sprintf('SSIM%d.png', k, k2));
saveas(gcf, fileC);
allSsim(k, k2) = ssim(image1, image2); % Compute ssim
allSsim(k2, k) = allSsim(k, k2); % Make symmetric.
end
end
The above code works perfectly except the subtitle. May I know how to print the k, k2 values in a figure title so that I understand which images are compared to draw the map? Any suggestion/help would be appreciated. Thanks.
6 comentarios
Image Analyst
el 16 de En. de 2022
It seems like subtitle does not work when there is an image in the axes. It works for plot() but not with imshow(). So you'll just have to have two lines.
figure();
imshow(im2double(ssimmap),[])
caption = sprintf('Local SSIM Map with Global SSIM Value: %.4f', ssimval);
title(caption)
subcaption = sprintf('%s\nk = %d, k2 = %d', caption, k, k2);
% subtitle(subcaption)
title(subcaption)
Anu
el 16 de En. de 2022
Thanks, @Image Analyst, for the insights. However, this above code gives me respective k and k2 values in each figure, not anything for the 'Local SSIM Map with Global SSIM Value: %.4f', ssimval.
I was wondering if it is possible to get the output all together in a title. I actually don't need the subtitle, but I am afraid if the title is too lengthy that it goes beyond the size of the figure.
Thanks
Image Analyst
el 16 de En. de 2022
Exactly what do you consider the "output" and how can you put that into a string that is the title? Please show an example of what you'd like the title to look like.
Anu
el 16 de En. de 2022
Sorry for the confusion. If k=1, and k2 = 2, and ssimval = 0.876, all I want to show in the title of the figure is:
Local SSIM Map with Global SSIM Value: 0.876 for k = 1 and k2 = 2
Since the images are shown in a for loop, the SSIM value, k, k2 will change for the respective cases.
Hope this clears what I want to print in the title of the figure.
Image Analyst
el 16 de En. de 2022
@Anu so simply get rid of the backslash n
folder = 'C:\Users\anusu\Downloads\figures\New folder';
filePattern = fullfile(folder, '*.tif');
f=dir(filePattern);
files={f.name};
numImages = numel(files);
allSsim = ones(numImages, numImages);
for k = 1 : numImages - 1
fullFileName1 = fullfile(folder, files{k});
image1 = imread(fullFileName1);
for k2 = k + 1 : numImages
fullFileName2 = fullfile(folder, files{k2});
image2 = imread(fullFileName2);
[ssimval,ssimmap] = ssim(image1,image2);
figure();
imshow(im2double(ssimmap),[])
impixelinfo;
caption = sprintf('Local SSIM Map with Global SSIM Value: %.4f for k = %d, k2 = %d', ssimval, k, k2);
title(caption)
fileC = fullfile(folder, sprintf('SSIM%d.png', k, k2));
saveas(gcf, fileC);
allSsim(k, k2) = ssim(image1, image2); % Compute ssim
allSsim(k2, k) = allSsim(k, k2); % Make symmetric.
end
end

Anu
el 16 de En. de 2022
@Image Analyst Ohh I tried this before but without removing \n, and it didn't work. Now it makes sense and thanks so much!
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!