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