Image quality and dimension
    3 views (last 30 days)
  
       Show older comments
    
    Aravind Prabhu Gopala Krishnan
 on 2 Aug 2021
  
    
    
    
    
    Commented: Aravind Prabhu Gopala Krishnan
 on 2 Aug 2021
            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 
0 Comments
Accepted Answer
  Matt J
      
      
 on 2 Aug 2021
        
      Edited: Matt J
      
      
 on 2 Aug 2021
  
      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
More Answers (0)
See Also
Categories
				Find more on Frequency Transformations in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
