How to convert an image to frequency domain in MATLAB?

조회 수: 98 (최근 30일)
Nayana  Hammini
Nayana Hammini 2015년 12월 27일
댓글: Seyed Amirreza Kabodian 2022년 8월 27일
I did it with this below code.
r=imread('C:\Users\Nayana22\Desktop\k.jpg');
figure,imshow(r)
F=fft2(r);
S=fftshift(log(1+abs(F)));
figure,imshow(S,[])
The output of second figure is full blank white page. Please can u tell me what's mistake with this code?
My MATLAB version is R2012a.
Thank u

채택된 답변

Image Analyst
Image Analyst 2015년 12월 27일
r is not an RGB image is it? Verify and run this and tell me what it says
[rows, columns, numberOfColorChannels] = size(r)
I know this works for the RGB demo image because I convert it to grayscale:
grayImage = imread('peppers.png');
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 1, 1);
imshow(grayImage, []);
fontSize = 20;
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Display the original gray scale image.
subplot(2, 1, 2);
F=fft2(grayImage);
S=fftshift(log(1+abs(F)));
imshow(S,[]);
title('Spectrum Image', 'FontSize', fontSize, 'Interpreter', 'None');
  댓글 수: 3
roni zidane
roni zidane 2019년 2월 18일
Hi @Image analyst,
How will i reconstruct my filtered freqency domain image data to original image after using the following code..
F=fft2(grayImage);
S=fftshift(log(1+abs(F)));
W = wiener2(S); % filter a gray image by 3x3 neighbourhood in freq domain.
% now i want to get a resulting filtered gray image
% which steps to follow?
FiltImg = ... % how do i convert the freq domain to spacial/time domain?
Seyed Amirreza Kabodian
Seyed Amirreza Kabodian 2022년 8월 27일
why do you do this?
--> S=fftshift(log(1+abs(F)));
is that any reason for this ?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by