Why shift, take absolute value and perform log transform to the frequency spectrum of an image obtained by fft2?

63 ビュー (過去 30 日間)
I have to obtain the frequency spectrum of a grayscale image using FFT in MATLAB and plot the spectrum. I used fft2() and plotted the output.
I watched a tutorial on plotting frequency spectrum and in that, they perform fftshit(), take the absolute value, apply a log transformation, scale pixels using mat2gray() and then convert into uint8 before plotting the spectrum.
im2uint8(mat2gray(log(abs(fft_shifted)+1)))
My question is, is that necessary to perform all those steps before plotting the frequency spectrum?
I know fftshift() is used to center the spectrum around 0th frequency coefficient. But what is the use of performing other functions?
I plotted the frequency spectrum without shifting, after shifting, and after applying the above-mentioned steps.
After this, I have to apply a low pass filter to the grayscale image and compare frequency spectrums. (This is a homework question)
Any advice is much appreciated. Thank you!

回答 (2 件)

yanqi liu
yanqi liu 2021 年 11 月 8 日
im2uint8(mat2gray(log(abs(fft_shifted)+1)))
sir,i think
abs(fft_shifted)+1 to avoid log(0) or log(neg)
log to display result in log space,to avoid some data too big with some data too small

Chris
Chris 2021 年 11 月 8 日
take the absolute value
The log of a negative number is undefined, which would make for a boring image.
apply a log transformation
It's likely some intensities will be orders of magnitude higher than some others. Applying a log scale allows you to see the smaller values as well. Otherwise, the image will be boring.
scale pixels using mat2gray() and then convert into uint8
I don't know what function you're using to display the image, but functions like imshow() expect integers on a 0 to 255 scale (an 8-bit pixel map). im2uint8(mat2gray()) accomplishes that scaling.
  2 件のコメント
Ilya Grishanovich
Ilya Grishanovich 2022 年 4 月 21 日
How to take the absolute value for 2D spectrum?
I have 2D spectrum with positive and negative signals, I want to make all signals positive.
How to make it?
Chris
Chris 2022 年 4 月 21 日
編集済み: Chris 2022 年 4 月 21 日
If it's in matrix form, like an image, abs() will make all points positive.

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by