hi ..i am writing a code for quadrant dynamic histogram equalization...but i am getting an error while mapping back to the original image as 'Attempted to access map(0); index must be a positive integer or logical.'..i have attached the code
1 回表示 (過去 30 日間)
古いコメントを表示
clc;
close all;
clear all;
WAAD_img= imread('C:\Users\Public\Pictures\Sample Pictures\image14.jpg');
WAAD_img= rgb2gray(WAAD_img);
% WAAD_hist=Fn_get_hist(WAAD_img,R,C);
WAAD_hist=imhist(uint8(WAAD_img))';
m = zeros(1,5);
[R C] = size(WAAD_img);
for i = 1 : 256
if WAAD_hist(i)>R*C/100000; m(1) = i; break;
end
end
for i = 256 :-1: 1
if WAAD_hist(i)>R*C/100000; m(5) = i; break;
end
end
cdf_data = cumsum(WAAD_hist)/(R*C);
[val idx] = find(cdf_data >= 0.25 &cdf_data < 0.50);
if size(idx) ~= 0
m(2) = idx(1);
m(3) = idx(end);
else
[val idx] = find(cdf_data > 0);
m(2) = m(1);
m(3) = m(1);
end
[val idx] = find(cdf_data >= 0.75);
m(4) = idx(1)-1;
% cliping
avgFreqOfimage = floor(R*C/256);
chist_data = zeros(1,256);
for i = 1 :256
if WAAD_hist(i) >= avgFreqOfimage
chist_data(i) = avgFreqOfimage;
else
chist_data(i) = WAAD_hist(i);
end
end
span= zeros(1,4);
for i = 1 : 4
span(i) = m(i+1)-m(i);
end
range = round(256*span/sum(span));
sepPosition = cumsum([0 range]);
new_cdf= zeros(1,256);
map = zeros(1,256);
for i = 1 : 4
if i==1
temp = cumsum(chist_data(m(i):m(i+1)));
new_cdf(m(i):m(i+1)) = temp/temp(end);
map(m(i):m(i+1)) = round(range(i)*new_cdf(m(i):m(i+1)));
else
temp = cumsum(chist_data(m(i):m(i+1)));
new_cdf(m(i):m(i+1)) = temp/temp(end);
map(m(i):m(i+1)) = round(range(i)*new_cdf(m(i):m(i+1))+sepPosition(i));
end
end
QDHE_img = zeros(R,C);
for i = 1: R
for j = 1: C
QDHE_img(i,j) = map(WAAD_img(i,j));
end
end
QDHE_img = uint8(QDHE_img);
figure, imshow(QDHE_img)
1 件のコメント
Lalitha Susmitha Kothamasu
2019 年 2 月 7 日
I am not able to understand the approach you used in the code can u please help me
採用された回答
その他の回答 (1 件)
DHIVYA BHARKAVI
2017 年 12 月 19 日
Sir, Please help to my project your Quandrant Dynamic histogram Equalization in Version Matlab 2013a
1 件のコメント
DGM
2023 年 11 月 27 日
編集済み: DGM
2023 年 11 月 27 日
The attached code (and the identical code in the other redundant questions-as-answers that have been deleted) is basically the same as OP's code with Walter's fix included. It runs on R2009b and R2015b just fine so long as the input image depth is appropriate, and I see no reason it shouldn't be the same in R2013a.
Was the code throwing an error because the input to rgb2gray() was already single channel? Probably. Certainly, cameraman.tif would be. The call to rgb2gray() should only be done if the image is RGB.
% any practical use of rgb2gray() requires extra code
if size(WAAD_img,3) == 3
WAAD_img = rgb2gray(WAAD_img);
elseif size(WAAD_img,3) ~= 1
error('this image is neither RGB nor I')
end
Was the code throwing an error because IPT wasn't installed? Maybe. rgb2gray() and imshow() would still be in IPT at the time.
Was it something else? This is why you need to actually describe the problem. "Please help" isn't effective at troubleshooting in a timely manner.
参考
カテゴリ
Help Center および File Exchange で Image Filtering and Enhancement についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!