How to compare the saved names of two images stored in different folders ?
조회 수: 2 (최근 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에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!