Compare each image with another
조회 수: 4 (최근 30일)
이전 댓글 표시
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
KALYAN ACHARJYA
2019년 7월 2일
@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....
채택된 답변
Image Analyst
2019년 7월 2일
I suggest you don't store all the images in a cell array because you might run out of memory if you have a lot of them. I'd just use a double for loop:
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);
allSsim(k, k2) = ssim(image1, image2) % Compute ssim
allSsim(k2, k) = allSsim(k, k2); % Make symmetric.
end
end
댓글 수: 12
Image Analyst
2019년 7월 14일
I'm attaching a kmeans demo for grayscale and color. Adapt as needed. Good luck. ?️
추가 답변 (1개)
Anu
2022년 1월 16일
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
Image Analyst
2022년 1월 16일
@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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/864375/image.png)
Anu
2022년 1월 16일
@Image Analyst Ohh I tried this before but without removing \n, and it didn't work. Now it makes sense and thanks so much!
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!