MATLAB圖像增強程序舉例

1.灰度變換增強程序


% GRAY TRANSFORM
clc;
I=imread('pout.tif');
imshow(I);
J=imadjust(I,[0.3 0.7],[0 1],1);??%transforms the walues in the %intensity image I to values in J by linealy mapping %values between 0.3 and 0.7 to values between 0 and 1.
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],0.5);??% if GAMMA is less than 1,the ?mapping si weighted toward higher (brighter)
%output values.
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],1.5);??% if GAMMA is greater than 1,the mapping si weighted toward lower (darker)
%output values.
figure;
imshow(J)
J=imadjust(I,[0.3 0.7],[0 1],1);??% If TOP<BOTTOM,the output image is reversed,as in a photographic negative.
figure;
imshow(J);


?

2.直方圖灰度變換

%直方圖灰度變換
[X,map]=imread('forest.tif');
I=ind2gray(X,map);%把索引圖像轉換為灰度圖像
imshow(I);
title('原圖像');
improfile%用鼠標選擇一條對角線,顯示線段的灰度值
figure;subplot(121)
plot(0:0.01:1,sqrt(0:0.01:1))
axis square
title('平方根灰度變換函數')
subplot(122)
maxnum=double(max(max(I)));%取得二維數組最大值
J=sqrt(double(I)/maxnum);%把數據類型轉換成double,然后進行平方根變換
%sqrt函數不支持uint8類型
J=uint8(J*maxnum);%把數據類型轉換成uint8類型
imshow(J)
title('平方根變換后的圖像')

3.直方圖均衡化程序舉例

% HISTGRAM EAQUALIZATION
clc;
% Clear command window

I=imread('tire.tif');
% reads the image in tire.tif into I

imshow(I);
% displays the intensity image I with 256 gray levels

figure;
%creates a new figure window

imhist(I);
% displays a histogram for the intensity image I

J=histeq(I,64);
% transforms the intensity image I,returning J an intensity

figure;
%image with 64 discrete levels

imshow(J);
figure;
imhist(J);
J=histeq(I,32);
%transforms the intensity image ,returning in % J an intensity

figure;
%image with 32 discrete levels

imshow(J);
figure;
imhist(J);

4.直方圖規定化程序舉例

% HISTGRAM REGULIZATION
clc;
%Clear command window
I=imread('tire.tif');
%reads the image in tire.tif into I

J=histeq(I,32);
%transforms the intensity image I,returning in

%J an intensity image with 32 discrete levels
[counts,x]=imhist(J);
%displays a histogram for the intensity image I

Q=imread('pout.tif');
%reads the image in tire.tif into I

figure;
imshow(Q);
figure;
imhist(Q);
M=histeq(Q,counts);
%transforms the intensity image Q so that the

%histogram of the output image M approximately matches counts
figure;
imshow(M);
figure;
imhist(M);

空域濾波增強部分程序

1.線性平滑濾波
I=imread('eight.tif');
J=imnoise(I,'salt & pepper',0.02);
subplot(221),imshow(I)
title('原圖像')
subplot(222),imshow(J)
title('添加椒鹽噪聲圖像')
K1=filter2(fspecial('average',3),J)/255;%應用3*3鄰域窗口法
subplot(223),imshow(K1)
title('3x3窗的鄰域平均濾波圖像')
K2=filter2(fspecial('average',7),J)/255;%應用7*7鄰域窗口法
subplot(224),imshow(K2)
title('7x7窗的鄰域平均濾波圖像')

?

?

2.中值濾波器
MATLAB中的二維中值濾波函數medfit2來進行圖像中椒鹽躁聲的去除
%IMAGE NOISE REDUCTION WITH MEDIAN FILTER
clc;
hood=3;%濾波窗口
[I,map]=imread('eight.tif');
imshow(I,map);
noisy=imnoise(I,'salt & pepper',0.05);
figure;
imshow(noisy,map);
filtered1=medfilt2(noisy,[hood hood]);
figure;
imshow(filtered1,map);
hood=5;
filtered2=medfilt2(noisy,[hood hood]);
figure;
imshow(filtered2,map);
hood=7;
filtered3=medfilt2(noisy,[hood hood]);
figure;
imshow(filtered3,map);
3. 4鄰域8鄰域平均濾波算法
% IMAGE NOISE REDUCTION WITH MEAN ALGORITHM
clc;
[I,map]=imread('eight.tif');
noisy=imnoise(I,'salt & pepper',0.05);
myfilt1=[0 1 0;1 1 1;0 1 0];%4鄰域平均濾波模版
myfilt1=myfilt1/9;%對模版歸一化
filtered1=filter2(myfilt1,noisy);
imshow(filtered1,map);
myfilt2=[1 1 1;1 1 1;1 1 1];
myfilt2=myfilt2/9;
filtered2=filter2(myfilt2,noisy);
figure;
imshow(filtered2,map);

頻域增強程序舉例

1.低通濾波器
% LOWPASS FILTER
clc;
[I,map]=imread('eight.tif');
noisy=imnoise(I,'gaussian',0.05);
imshow(noisy,map);
myfilt1=[1 1 1;1 1 1;1 1 1];
myfilt1=myfilt1/9;
filtered1=filter2(myfilt1,noisy);
figure;
imshow(filtered1,map);
myfilt2=[1 1 1;1 2 1;1 1 1];
myfilt2=myfilt2/10;
filtered2=filter2(myfilt2,noisy);
figure;
imshow(filtered2,map);
myfilt3=[1 2 1;2 4 2; 1 2 1];
myfilt3=filter2(myfilt3,noisy);
figure;
imshow(filtered3,map);
2.布特沃斯低通濾波器圖像實例
I=imread('saturn.png');
J=imnoise(I,'salt & pepper',0.02);
subplot(121),imshow(J)
title('含噪聲的原圖像')
J=double(J);
f=fft2(J);
g=fftshift(f);
[M,N]=size(f);
n=3;d0=20;
n1=floor(M/2);n2=floor(N/2);
for i=1:M;
for j=1:N;
d=sqrt((i-n1)^2+(j-n2)^2);
h=1/(1+0.414*(d/d0)^(2*n));
g(i,j)=h*g(i,j);
end
end
g=ifftshift(g);
g=uint8(real(ifft2(g)));
subplot(122),imshow(g)
title('三階Butterworth濾波圖像')

色彩增強程序舉例

1.真彩色增強實例:
%真彩色圖像的分解
clc;
RGB=imread('peppers.png');
subplot(221),imshow(RGB)
title('原始真彩色圖像')
subplot(222),imshow(RGB(:,:,1))
title('真彩色圖像的紅色分量')
subplot(223),imshow(RGB(:,:,2))
title('真彩色圖像的綠色分量')
subplot(224),imshow(RGB(:,:,3))
title('真彩色圖像的藍色分量')
2.偽彩色增強舉例:
I=imread('cameraman.tif');
imshow(I);
X=grayslice(I,16);%thresholds the intensity image I using
%threshold values 1/16,2/16,…..,15/16,returning an indexed %image in X
figure;
imshow(X,hot(16));
?
3.假彩色增強處理程序舉例
[RGB]=imread('ghost.bmp');
imshow(RGB);
RGBnew(:,:,1)=RGB(:,:,3);
RGBnew(:,:,2)=RGB(:,:,1);
RGBnew(:,:,3)=RGB(:,:,2);
figure;
subplot(121);
imshow(RGB);
subplot(122);
imshow(RGBnew);

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/253639.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/253639.shtml
英文地址,請注明出處:http://en.pswp.cn/news/253639.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Design Compiler指南——設計綜合過程

在前面一章介紹完施加約束之后&#xff0c;接下來要做的工作就是將設計進行綜合編譯(compile)&#xff0c;本文我們將主要討論綜合編譯的過程。主要分為這樣幾個部分&#xff1a; 優化的三個階段及其特點編譯的策略編譯層次化的設計 一、優化的三個階段 這一節我們介紹Design …

How to find Material based on Sales Organization and Distribution Channel

Fetch data from Database View /BEV1/RBEA_V Fields: VKORG - Sales Organization VTWEG - Distribution Channel MATNR - Material Number 轉載于:https://www.cnblogs.com/JulietLV/p/7436028.html

iOS開發 iOS10兼容訪問http

添加NSAppTransportSecurity的字典會自動變成 AppTransportSecurity再添加 allow Arbitary Loads Boolean YES轉載于:https://www.cnblogs.com/diweinan/p/6233052.html

django 利用PIL 保存圖片

在使用django時不知道怎么保存圖片&#xff0c;又不想用它的form &#xff0c;在網上找了許久&#xff0c;終于找到個解決方案&#xff0c;利用PIL.image 將POST上來的圖片保存到media目錄下&#xff0c;然后再修改models from PIL import Imagescreen_name request.POST.get(…

圖像轉灰度圖

MyYuanLaiPic imread(e:/image/matlab/darkMouse.jpg);%讀取RGB格式的圖像 MyFirstGrayPic rgb2gray(MyYuanLaiPic);%用已有的函數進行RGB到灰度圖像的轉換 [rows , cols , colors] size(MyYuanLaiPic);%得到原來圖像的矩陣的參數 MidGrayPic zeros(rows , cols);…

Design Compiler指南——后綜合過程

本文我們著重討論使用Design Compiler綜合大型設計時要注意的一些問題&#xff0c;比如怎樣調整綜合方法&#xff0c;出現約束違反后怎樣修正&#xff0c;怎樣給不同的子模塊作時序和負載預算&#xff0c;以及給整個設計在具體綜合之前先作一個預估(Design Exploration)等等。 …

web worker原理 SSE原理

第一部分 什么是 web worker&#xff1f; 我們一直強調JavaScript是單線程的&#xff0c;但是web worker的出現使得JavaScript可以在多線程上跑&#xff0c;只是web worker本身適合用于一些復雜的、耗費cpu的運算&#xff0c;不能操作window、document、parent對象&#xff0c…

如何尋回xp盤符丟失的數據

分區丟失是比較常見的數據恢復案例&#xff0c;需要注意&#xff0c;分區丟失后不要再重建新的分區。保護好資料丟失現場&#xff0c;可以最大程度的恢復出資料。具體的恢復方法看正文了解。 工具/軟件&#xff1a;星空數據恢復軟件 步驟1&#xff1a;先百度搜索并下載程序打開…

afx_msg函數意思

應用程序框架產生的消息映射函數 例如&#xff1a;afx_msg void OnBnClickedButton1(); 其中 afx_msg為消息標志&#xff0c;它向系統聲明&#xff1a;有消息映射到函數實現體&#xff1b; 而在map宏定義中&#xff0c;就有具體消息和此函數的映射定義&#xff08;可以是自定義…

文件得編碼和文件名的編碼是不一樣的

1.新知識&#xff0c;通過文件后墜名的編碼判斷文件類型&#xff0c;可以有效的防止腳本文件偽裝為正常得文件。 2.攔截器和過濾器。 過濾器只能夠在http請求和回復的時候進行處理。 但是攔截器可以在很多地方攔截&#xff0c;例如程序拋異常等都可以捕獲的到。還可以進行權限得…

Visual computing——概述

Visual Computing&#xff08;視覺計算&#xff09;是所有處理二維圖像和三維模型的計算機科學學科的總稱&#xff0c;即計算機圖形學、圖像處理、可視化、計算機視覺、虛擬和增強現實、視頻處理&#xff0c;但也包括模式識別、人機交互、機器學習等方面。核心挑戰是視覺信息&a…

推薦!手把手教你使用Git

一&#xff1a;Git是什么&#xff1f; Git是目前世界上最先進的分布式版本控制系統。 二&#xff1a;SVN與Git的最主要的區別&#xff1f; SVN是集中式版本控制系統&#xff0c;版本庫是集中放在中央服務器的&#xff0c;而干活的時候&#xff0c;用的都是自己的電腦&#xff0…

I2C協議學習

I2C Bus(Inter-Integrated Circuit Bus) 最早是由Philips半導體&#xff08;現被NXP收購&#xff09;開發的兩線式串行總線&#xff0c;常用于微控制器與外設之間的連接。 一、概述 以下是 I2C 總線的一些特性&#xff1a; 只需要兩條總線&#xff1b;一條串行數據線 (SDA) 和…

ajax的簡單介紹

響應主體&#xff0c;就是服務器給我們返回的結果內容&#xff08;瀏覽器里的responsive&#xff09; 請求主體&#xff0c;是我們給服務器的數據 輸入域名發起一次請求&#xff0c;得到的可能是標簽&#xff0c;標簽可能還要在發一次請求 post怎么發請求&#xff1a;form表單 …

DM365 color space

YUV的幾種格式 420P&#xff1a;420P數據的存放方式一般是先存放Y&#xff0c;然后存放U&#xff0c;最后存放V的數據&#xff0c;每一個像素使用12bits(1.5BYTE)保存。 422P&#xff1a;422P數據的存放方式也是先存放Y&#xff0c;然后存放U&#xff0c;最后存放V的數據&…

JavaScript 標準參考教程-閱讀總結(三)

1、DOM模型 DOM 是 JavaScript 操作網頁的接口&#xff0c;全稱為“文檔對象模型”&#xff08;Document Object Model&#xff09;。它的作用是將網頁轉為一個 JavaScript 對象&#xff0c;從而可以用腳本進行各種操作&#xff08;比如增刪內容&#xff09;。 1&#xff09;do…

P1136 迎接儀式

P1136 迎接儀式 題目描述 LHX教主要來X市指導OI學習工作了。為了迎接教主&#xff0c;在一條道路旁&#xff0c;一群Orz教主er穿著文化衫站在道路兩旁迎接教主&#xff0c;每件文化衫上都印著大字。一旁的Orzer依次擺出“歡迎歡迎歡迎歡迎……”的大字&#xff0c;但是領隊突然…

云服務器 VNC 遠程連接

此服務器買來是為了搭建IC EDA云的&#xff0c;因此選用的是centOS 6的環境&#xff0c;對各EDA軟件兼容較好。本人手頭拮據&#xff0c;因此買的是騰訊云活動期間的云服務器&#xff0c;只能說夠用吧。 一、桌面安裝 在云服務器控制臺登陸上遠程主機&#xff0c;依次執行下列…

Python自動化測試框架有哪些?

作者 | KITTY GUPTA 譯者 | 張健欣 令開發者萬分高興的是&#xff0c;開發自己的測試框架的日子終于結束了。以前&#xff0c;開發團隊接手一個項目并開始開發時&#xff0c;除了項目模塊的實際開發之外&#xff0c;他們不得不為這個項目構建一個自動化測試框架。一個測試框架應…

面試題——4種數組去重的方法

數組去重或者其衍生作為筆試題或者機試題出現的幾率也是很大的&#xff0c;寫出的方法越多&#xff0c;則讓面試官覺得你思維越開闊&#xff0c;那么成功的幾率當然就大了。 廢話不多說&#xff0c;下面來說說下面我整理的4中數組去重的方法 方法一&#xff1a; findInArr方法s…