Image quality and dimension

조회 수: 1 (최근 30일)
Aravind Prabhu Gopala Krishnan
Aravind Prabhu Gopala Krishnan 2021년 8월 2일
Hello here i attached my processed image using convn, the problem is when I process one image and save it to my local machine its perfect, but if I process 5000 images using same pipeline and save that 5000 images, the image shape and structures are collapsed I dont know why, I attached my code and processed images, if anybody know please try to help.
This is my single processed image.
If i use 5000 image in the same pipeline the result be like this
Both are same image filtered using same pipeline.
Here is my code
infolder = 'C:\Users\91894\Desktop\matlab\Dataset\images_001\images'
outfolder = 'C:\Users\91894\Desktop\matlab\Dataset\images_001\processed image'
imgFiles = dir([infolder,filesep,'\*.png']) ;
N = length(imgFiles) ;
refback = zeros(25, 25);
for i = 1:N
thisFile = [infolder,filesep,imgFiles(i).name] ;
[filepath,name,ext] = fileparts(thisFile) ;
outFile = [outfolder,filesep,[name,ext]] ;
I = imread(thisFile) ;
J = imresize(I,[256 256]);
for f = 1:4
SpatDog = fspecial('gaussian',25,0.732) - fspecial('gaussian',25,0.785);
FreqDog = fftshift(fft2(fftshift(SpatDog)));
Y = abs(FreqDog)
refback = refback + im2double(Y);
end
refback = (1/4) * refback;
Y = fftshift(ifft2(fftshift(refback)));
conv = convn(J,Y);
imwrite(conv,outFile) ;
end
I need to write the image to my laptop as its shown in the first image

채택된 답변

Matt J
Matt J 2021년 8월 2일
편집: Matt J 2021년 8월 2일
Well, I don't know if this is intentional, but every new image in the loop gets filtered by a different kernel because refback never gets reset to zero and just keeps accumulating in the line,
refback = refback + im2double(Y);
If the filter kernel is supposed to be constant, the creation of Y should be pulled out of the loop, as below. Also, since Y is generated using FFTs, it is recommendable to ensure that Y is real-valued.
infolder = 'C:\Users\91894\Desktop\matlab\Dataset\images_001\images'
outfolder = 'C:\Users\91894\Desktop\matlab\Dataset\images_001\processed image'
imgFiles = dir([infolder,filesep,'\*.png']) ;
N = length(imgFiles) ;
refback = zeros(25, 25);
for f = 1:4
SpatDog = fspecial('gaussian',25,0.732) - fspecial('gaussian',25,0.785);
FreqDog = fftshift(fft2(fftshift(SpatDog)));
Y = abs(FreqDog)
refback = refback + im2double(Y);
end
refback = (1/4) * refback;
Y = fftshift(ifft2(fftshift(refback)));
Y=real(Y);
for i = 1:N
thisFile = [infolder,filesep,imgFiles(i).name] ;
[filepath,name,ext] = fileparts(thisFile) ;
outFile = [outfolder,filesep,[name,ext]] ;
I = imread(thisFile) ;
J = imresize(I,[256 256]);
conv = convn(J,Y);
imwrite(conv,outFile) ;
end
  댓글 수: 1
Aravind Prabhu Gopala Krishnan
Aravind Prabhu Gopala Krishnan 2021년 8월 2일
Thank you very much it worked great.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by