Problem with the saved output of a high spatial frequency pass filtered image
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello -
I am trying to write a file with the output from a hgih spatial frequency pass filter. When the figure shows up in MATLAB it looks like what I expect. However, when I look at the written file, it looks different (and wrong!). I am running this function on many images and cannot save the figure each time.
Below is the relevant code. Basically the figure that pops up of B2 is what I expect, but in my folder, the saved image is much different and not what I need.
Anyone know how to help me with this? Thanks so much in advance!
files = {
'longImagename.jpg', ...
'otherLongimagename.jpg', ...
'andsoforth.jpg', ...
};
nfiles = size(files,2);
for n = 1:nfiles
% read in image:
[tmp,current_file,ext] = fileparts(files{n});
im = imread(strcat(current_file,ext));
% HSF - Create the HIGH pass input arguments
A = fft2(double(im)); % compute FFT of the grey image
A1=fftshift(A); % frequency scaling
% Gaussian Filter Response Calculation
[M N]=size(A); % image size
R=10; % filter size parameter
X=0:N-1;
Y=0:M-1;
[X Y]=meshgrid(X,Y);
Cx=0.5*N;
Cy=0.5*M;
Lo=exp(-((X-Cx).^2+(Y-Cy).^2)./(2*R).^2);
Hi=1-Lo; % High pass filter=1-low pass filter
% Filtered image=ifft(filter response*fft(original image))
J=A1.*Lo;
J1=ifftshift(J);
B1=ifft2(J1);
K=A1.*Hi;
K1=ifftshift(K);
B2=ifft2(K1); %this is the HSF one
figure;
imshow(B2,[]);
% save HSF to file:
outfilename = sprintf('%s_HSF.jpg',current_file);
imwrite(B2,outfilename);
end
2 Kommentare
Elissa Aminoff
am 18 Okt. 2021
Did you ever solve this problem? I am likely running into the same issue ...
thanks!
Image Analyst
am 18 Okt. 2021
@Elissa Aminoff, since it was over a year ago, I guess it was solved. You'd have better luck posting your own new question with your data and code.
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!