19 Mart 2012 Pazartesi

Matlab - histeq implementation

Matlab da histogram equalization için kullanılan histeq fonksiyonunun implementasyonu:

***F bir gray scale input image****

function image_histeq(F)

I = imread(F);

%histeq
J = histeq(I);

%Output image of our algorithm and its histogram

width = size(I,1);
height = size(I,2);
MN = width * height;

Hist = uint8(zeros(width , height));

frequency = zeros(256 , 1);

probability = zeros(256,1);


for i = 1 : width
for j = 1 : height
value = I(i , j);
frequency(value + 1) = frequency(value + 1) + 1;
probability(value + 1) = frequency(value + 1) / MN;
end
end

sum = 0;
bits = 255;

probCount = zeros(256 , 1);

cum = zeros(256 , 1);


output = zeros(256 , 1);

for i = 1 : size(probability)
sum = sum + frequency(i);
cum(i) = sum;
probCount(i) = cum(i) / MN;
output(i) = round(probCount(i) * bits);
end


for i = 1 : width
for j = 1 : height

Hist(i,j) = output(I(i , j) + 1);

end
end

%display all

subplot(3,2,1);
imshow(I);
title('Input Image');
subplot(3,2,2);
imhist(I);
title('Input image histogram');
subplot(3,2,3);
imshow(J);
title('Output image of histeq function');
subplot(3,2,4);
imhist(J);
title('histeq function histogram');
subplot(3,2,5);
imshow(Hist);
title('Output image of our algorithm');
subplot(3,2,6);
imhist(Hist);
title('our algorithm histogram');


return

Download Code

4 yorum:

Adsız dedi ki...

soru: imhist() fonksiyonu ile bir histogram grafiği oluşuyor bu grafikte: gri değerlere(yatay eksen) karşılık tekrarlanan toplam pixel sayiları(düşey eksen görülüyor; benim sorum :mathlabta herbir gri degerin toplam kaç pixelden oluştugunu gosteren (dizi şeklinde) (histeq() fonksiyonun bir türevi olabilir) fonsiyon var mı biliyor musunuz ? yardımcı olursanız sevinirim.sağolun

Adsız dedi ki...

selam bu projeyi im proc.dersindemi yaptınız guzelmiş beğendim eskiden almıştım bu dersi anlaşılan ilerleme var

Bahar çağlar dedi ki...

evet dersin ödeviydi ;)

Bahar çağlar dedi ki...

imhist zaten gri değerin image da kaç tane olduğunu veriyor image içindeki herbir değeri alıp imhist ile sayısı bulunabilir her bir değer için imhist çalıştırıldığı düşünüldüğünde. BU şekilde yapılabilir ama hazır fonkisyon var mıdır bilmiyorum bakmak lazım. Ama implementationı da zor olmasa gerek :)

Yorum Gönder