フィルターのクリア

How to transform an gray scale image from frequency to spatial domain ?

15 ビュー (過去 30 日間)
Ruhul Amin
Ruhul Amin 2015 年 12 月 12 日
コメント済み: Sudeepto Mohanta 2021 年 8 月 2 日
I can transform a gray scale image from spatial domain to frequency domain. But when i transform that image form frequency to spatial domain using ifft() its not giving me the real image. What should i do?
Here is my code:
img = imread('sample.tif');
imgFFT = fft2(double(img));
img2 = ifft2(imgFFT);
I just want to simply transform an image to frequency domain and then re-transform it into original image. But that ifft2() function is not giving me the original image.

採用された回答

John D'Errico
John D'Errico 2015 年 12 月 12 日
Seems to work for me.
A = magic(10);
Af = fft2(A);
Ai = ifft2(Af);
norm(A - Ai)
ans =
3.3779e-14
  2 件のコメント
John D'Errico
John D'Errico 2015 年 12 月 13 日
My guess is the OP simply tested to see if the result was EQUAL to the start. Of course not. It will be in error, just as my test was. That does not make it different, just floating point trash.
Ruhul Amin
Ruhul Amin 2015 年 12 月 13 日
編集済み: Ruhul Amin 2015 年 12 月 13 日
Thanks for your response. Its working. I don't no why i getting wrong answer that time.. :)
img = imread('sample.TIF');
figure,imshow(img,'InitialMagnification','fit');
imgB = im2bw(img,0.2);
figure,imshow(imgB,[],'InitialMagnification','fit');
imgF = fftshift(fft2(imgB));
figure, imshow(imgF,[],'InitialMagnification','fit');
imgIF = ifft2(ifftshift(imgF));
figure, imshow(imgIF,[],'InitialMagnification','fit');
It's working perfectly.

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2015 年 12 月 12 日
This works fine for me:
grayImage = imread('cameraman.tif');
% Display the original gray scale image.
subplot(1, 2, 1);
imshow(grayImage, []);
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')
imgFFT = fft2(double(grayImage));
roundTripImage = ifft2(imgFFT);
whos roundTripImage
subplot(1, 2, 2);
imshow(roundTripImage, []);
title('After round trip to Fourier Domain', 'FontSize', fontSize, 'Interpreter', 'None');
How is your image different? Please attach sample.tif. What is it? Is it not gray scale? Is it color? Perhaps that might mess it up.
  5 件のコメント
Image Analyst
Image Analyst 2021 年 7 月 27 日
fft2() takes the 2-D fft of the image.
subplot(1, 2, n) takes a figure and has 1 row and 2 columns of plots (axes for images). n is the plot/image slot that the image goes into.
imshow() shows the image in the designated slot.
title() puts words above the image.
whos tells you information about the variable.
imread() reads in an image from disk, given a filename.
Sudeepto Mohanta
Sudeepto Mohanta 2021 年 8 月 2 日
thanks a lot.

サインインしてコメントする。


Nehal fawzy
Nehal fawzy 2019 年 4 月 6 日
any one help me
how i can transform image from spatial domain to neutrosophic domain with matlab code

Community Treasure Hunt

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

Start Hunting!

Translated by