How to compare the saved names of two images stored in different folders ?
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Stephen23
2020 年 2 月 9 日
編集済み: Stephen23
2020 年 2 月 9 日
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
その他の回答 (1 件)
Thiago Henrique Gomes Lobato
2020 年 2 月 9 日
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)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!