1

我在理解如何在對圖像執行直方圖均衡後如何更改灰度GIF圖像的顏色圖時遇到了一些麻煩。這個過程非常簡單,對於沒有相關色彩映射(如JPEG)的圖像壓縮類型,我已經將它用於灰度JPEG圖像。在GIF圖像上進行MATLAB直方圖均衡

clear 
clc 
[I,map] = imread('moon.gif'); 
h = zeros(256,1); %array value holds number of pixels with same value 
hmap = zeros(256,1); 
P = zeros(256,1); %probability that pixel intensity will appear in image 
Pmap = zeros(256,1); 
s = zeros(256,1); %calculated CDF using P 
smap = zeros(256,1); 
M = size(I,1); 
N = size(I,2); 
I = double(I); 

Inew = double(zeros(M,N)); 
mapnew = zeros(256,3); 
for x = 1:M; 
for y = 1:N; 
for l = 1:256; 
    %count pixel intensities and probability 
end 
end 
end 

for j = 2:256 
    for i = 2:j 
     %calculate CDF of P 
    end 
end 
s(1) = P(1); 
smap(1) = Pmap(1); 

for x = 1:M; 
for y = 1:N; 
for l = 1:256; 
    %calculates adjusted CDF and sets it to new image 
end 
end 
end 
mapnew = mapnew/256; 
Inew = uint8(Inew); 
I = uint8(I); 
subplot(1,2,1), imshow(Inew,map);  %comparing the difference between original map 
subplot(1,2,2), imshow(Inew,mapnew); %to'enhanced' colormap, but both turn out poorly 

所有在實際圖像的均衡方面都很好,但我不確定要怎樣改變顏色圖。我嘗試在顏色圖上執行與圖像相同的操作,但沒有骰子。

對不起,我不能發佈圖片,因爲我的低代表,但我會盡量提供所有的信息,我可以要求。

任何幫助將不勝感激。

+0

建議:您可以在[imgur](http://imgur.com/)上傳圖片併發布鏈接。更有特權的用戶可以將它們嵌入到您的問題中,直到您獲得自己的聲譽,並歡迎您加入! –

+0

如果你有它的正常圖像(灰度或真彩色)工作,你總是可以使用'ind2gray'或'ind2rgb'將圖像及其相應的色彩圖轉換爲第一種,然後執行您的程序。 fwiw MATLAB已經有'histeq'功能,適用於各種圖像 – Amro

+0

感謝您的幫助! ind2gray功能就像一個魅力。這是一個課堂作業,所以histeq不存在問題,除了確保您的代碼正常工作外。我也會記住使用imgur來提供圖像。再一次感謝你的幫助。 –

回答

0
function J=histeqo(I) 

    J=I; 
    [m,n]=size(I); 
    [h,d]=imhist(I); 
    ch=cumsum(h); // The cumulative frequency 
    imagesize=(m*n); // The image size lightsize=size(d,1);// The Lighting range 
    tr=ch*(lightsize/imagesize); // Adjustment function 

    for x=1:m 
     for y=1:n 
      J(x,y)=tr(I(x,y)+1); 
     end 
    end 
    subplot(1,2,1);imshow(J); 
    subplot(1,2,2);imhist(J); 
end 
+0

歡迎來到SO並感謝您的回答。請注意,這是一個說英語的網站。你可以編輯你的答案,只包括英文評論嗎? – Shai

+0

老兄,你不必寫在波斯!我會編輯它... – dariush