Image quality and dimension

2 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Frequency Transformations 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by