Effacer les filtres
Effacer les filtres

How to compare the saved names of two images stored in different folders ?

1 vue (au cours des 30 derniers jours)
I have 12 input images in the inputImages folder with names 001_in.png, 002_in.png ..... 012_in.png. Also I have the ground truths of these images 001_GT.png, 002_GT.png ... 012_GT.png in another folder named GroundTruth. I want to read and display these 12 images and for each of these 12 images, I have to calculate the PSNR value with respect to the ground truth stored in the GroundTruth folder. How will I get the ground truth for a particular input image ? Here's my code. I have tried to retrieve the image names and compare them. But, I am getting name1 = * , name 2 = * , last= 1×0 empty char array.
location1='G:\MTech\InputImages\*.png';
ds1=imageDatastore(location1)
while(hasdata(ds1))
I=read(ds1);
figure,imshow(I),title('Input Image');
[filepath1,name1,ext1] = fileparts(location1)
underlineLocation1 = strfind(name1, '_')
first = name1(1:underlineLocation1-1) %Getting the image name upto underscore
location2='G:\MTech\GroundTruth\*.png';
ds2=imageDatastore(location2)
while(hasdata(ds2))
ref=read(ds2);
figure,imshow(ref),title('Ground Truth');
[filepath2,name2,ext2] = fileparts(location2)
underlineLocation2 = strfind(name2, '_')
last = name2(1:underlineLocation2-1)
if first==last
[peaksnr, snr] = psnr(I, ref);
fprintf('\n The Peak-SNR value of final output is %0.4f', peaksnr);
end
end
end

Réponse acceptée

Stephen23
Stephen23 le 9 Fév 2020
Modifié(e) : Stephen23 le 9 Fév 2020
I don't think imageDatastore particularly helps in this case. Something like this:
P1 = 'G:\MTech\InputImages';
P2 = 'G:\MTech\GroundTruth';
for k = 1:12
F1 = sprintf('%03u_in.png',k);
F2 = sprintf('%03u_GT.png',k);
im = imread(fullfile(P1,F1));
rf = imread(fullfile(P2,F2));
[peaksnr,snr] = psnr(im,rf);
fprintf('\n The Peak-SNR value of final output is %0.4f', peaksnr);
end

Plus de réponses (1)

Thiago Henrique Gomes Lobato
You have a couple of errors in your code. Firstly to compare strings you must use the strcmp function, so
if strcmp(first,last)
instead of
if first==last
Second you're using the "fileparts" function in your image folder, not in the image that was actually loaded. By read you should also get the info and, from the info, get your file name (check here ):
[ref,info]=read(ds2);
figure,imshow(ref),title('Ground Truth');
[filepath2,name2,ext2] = fileparts(info.Filename)
  1 commentaire
Aiswarya C B
Aiswarya C B le 9 Fév 2020
Thank you so much for your answer.. This helped me to fix errors..

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by