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 件のコメント
yusuf zain
yusuf zain 2016 年 3 月 23 日
編集済み: yusuf zain 2016 年 3 月 23 日
thanks, but why when i tried to run this program, the image full black
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 Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by