-
大小: 3KB文件類型: .zip金幣: 2下載: 1 次發布日期: 2021-06-18
- 語言: Matlab
- 標簽:
資源簡介
數字圖像處理課程的第三次作業,包括圖像灰度直方圖的繪制、基于直方圖的各種空域處理。參考課本是岡薩雷斯的《數字圖像處理》

代碼片段和文件信息
clear;
clc;
file=dir(‘.\*.bmp‘);
figure(‘Numbertitle‘‘off‘‘Name‘‘圖像直方圖‘);
for?i=1:length(file)
????[img{i}colormap{i}]=imread(file(i).name);??%讀出每幅圖的索引和調色板
????img{i}=ind2gray(img{i}colormap{i});????%將索引圖轉為灰度圖
????%img{i}=im2double(img{i});
????subplot(44i);
????imhist(img{i});
????title(file(i).name);
end
figure(‘Numbertitle‘‘off‘‘Name‘‘原始圖像‘);
for?i=1:length(file)
????subplot(44i);
????imshow(img{i});
????title(file(i).name);
end
figure(‘Numbertitle‘‘off‘‘Name‘‘直方圖均衡化后的圖像‘);
for?i=1:length(file)
????img_histeq{i}=histeq(img{i});
????subplot(44i);
????imshow(img_histeq{i});
????title(file(i).name);
end
figure(‘Numbertitle‘‘off‘‘Name‘‘均衡化后的直方圖‘);
for?i=1:length(file)
????subplot(44i);
????imhist(img_histeq{i});
????title(file(i).name);
end
%%
city_elain=histmatch(img{1}imhist(img{4}));
figure(‘Numbertitle‘‘off‘‘Name‘‘直方圖匹配1‘)
subplot(231);imshow(img{1});title(‘citywall‘);
subplot(232);imshow(img{4});title(‘elain‘);
subplot(233);imshow(city_elain);title(‘city\_elain‘);
subplot(234);imhist(img{1});
subplot(235);imhist(img{4});
subplot(236);imhist(city_elain);
lena_woman=histmatch(img{8}imhist(img{12}));
figure(‘Numbertitle‘‘off‘‘Name‘‘直方圖匹配2‘)
subplot(231);imshow(img{8});title(‘lena‘);
subplot(232);imshow(img{12});title(‘woman‘);
subplot(233);imshow(lena_woman);title(‘lena\_woman‘);
subplot(234);imhist(img{8});
subplot(235);imhist(img{12});
subplot(236);imhist(lena_woman);
%%
function?img_out=histmatch(img_inhist)
[MN]=size(img_in);
hist_img=imhist(img_in);
%求T1:
a=zeros(2561);
T1=zeros(2561‘uint8‘);
a(1)=hist_img(1);
for?i=2:256
????a(i)=a(i-1)+hist_img(i);
????T1(i)=uint8(round(a(i)*255/(M*N)));
end
%求T2:
a=zeros(2561);
T2=zeros(2561‘uint8‘);
a(1)=hist(1);
for?i=2:256
????a(i)=a(i-1)+hist(i);
????T2(i)=uint8(round(a(i)*255/sum(hist)));
end
%求T3:
T3=zeros(2561);
a=zeros(2561);
for?i=1:256
????for?j=1:256
????????a(j)=abs(T1(i)-T2(j));
????end
????[~p]=min(a);
????T3(i)=uint8(p-1);
end
%outimage:
for?i=1:M
????for?j=1:N
????????img_out(ij)=T3(uint32(img_in(ij))+1);
????end
end
img_out=uint8(img_out);
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????519??2019-03-21?19:10??README.txt
?????文件????????2257??2019-03-15?01:02??task3_1.m
?????文件????????1705??2019-03-16?21:30??task3_2.m
?????文件????????1005??2019-03-15?17:53??task3_3.m
評論
共有 條評論