i have problem with : Attempted to access C(0); index must be a positive integer or logical. Error in HistogramEkualisasi (line 24)

1 次查看(过去 30 天)
"Error in HistogramEkualisasi (line 24)
hasil(baris, kolom) = C(Img(baris, kolom));"
Img = imread('D:\Pengolahan Citra Digital\Program MATLAB\car.jpg');
ukuran = size(Img);
jum_baris = ukuran(1);
jum_kolom = ukuran(2);
L = 256;
histog = zeros (L, 1);
for baris=1 : jum_baris
for kolom=1 : jum_kolom
histog(Img(baris, kolom)+1) = ...
histog(Img(baris, kolom)+1) +1;
end
end
alpha = (L-1) / (jum_baris * jum_kolom);
C(1) = alpha * histog(1);
for i=1 : L-1
C(i+1) = C(i) + round(alpha * histog(i+1));
end
for baris=1 : jum_baris
for kolom=1 : jum_kolom
hasil(baris, kolom) = C(Img(baris, kolom));
end
end
hasil = uint8(hasil);
imshow(hasil);

回答(1 个)

Walter Roberson
Walter Roberson 2016-3-23
Some of your counts will be 0, so Img(baris, kolom) will sometimes be 0. You are trying to index C(Img(baris, kolom)) so you are trying to index C(0) which is not permitted.
For consistency with your earlier code you should be referring to C(Img(baris,kolom)+1)
  2 个评论
Walter Roberson
Walter Roberson 2016-3-23
With the test image that I used, I do not get an all-black result.
Note that you read in a .jpg image. .jpg images are almost always RGB images, but you ignore everything except what corresponds to the red color plane. If the red color plane is empty you would not get anything useful out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by