matlab 画图像频谱图
生活随笔
收集整理的這篇文章主要介紹了
matlab 画图像频谱图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
matlab 畫圖像頻譜圖
- 需要注意的地方
- 圖像格式
- 代碼
- 處理單個圖像
- 批量處理
需要注意的地方
圖像格式
im2gray() 作用:將彩色圖或灰度圖轉換為灰度圖
代碼
處理單個圖像
img = imread("Homework+1\1.png"); % 用來將彩色圖轉換為灰圖,因為彩色圖的數值比起灰度圖處理起來非常不方便 img=im2gray(img); % FFT f = fft2(img); % FFT頻譜中心化 f = fftshift(f); % magnitude mag = abs(f); % phase phase = angle(f); % plot % 參數'[]'是為了將其值線性拉伸,log是為了更好顯示圖,加1是為了讓圖更亮(將所有值映射為正數) % 對數轉換的目的:經過log(X)變換后會變成負數,而log(X+1)則將所有的x值,映射成正數,數值范圍也更小一些。 subplot(311);imshow(img);title("Original image");axis on; subplot(312);imshow(log(mag+1),[]);title("Magnitude spectrum");axis on; subplot(313);imshow(phase,[]);title("Phase spectrum");axis on;批量處理
clc;close all; dir_path = '\'; img_list = dir(dir_path); % matlab讀取文件夾下的文件時,前兩個是空文件 for i=3:length(img_list)% 帶后綴的文件名img_name = img_list(i).name;% 不帶后綴的文件名,用于保存文件point = strfind(img_name,'.');name = img_name(1:point-1);% read imageoriginal_img = imread(strcat(dir_path,img_name));% 將圖像轉換為灰度圖img = im2gray(original_img);% FFTf = fft2(img);% FFT頻譜中心化f = fftshift(f);% magnitudemag = abs(f);% phasephase = angle(f);% plot% 參數'[]'是為了將其值線性拉伸,log是為了更好顯示圖,加1是為了讓圖更亮(將所有值映射為正數)figure(1)subplot(131);imshow(original_img,[]);title('Original image');axis on;subplot(132);imshow(log(mag+1),[]);title('Magnitude spectrum');axis on;subplot(133);imshow(phase,[]);title('Phase spectrum');axis on;saveas(gcf,strcat('result\',name),'jpg'); end總結
以上是生活随笔為你收集整理的matlab 画图像频谱图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: macos10.8.5原版系统dmg转i
- 下一篇: rapidjson!完美的C++解析js