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)

채택된 답변

Walter Roberson
Walter Roberson 2014년 2월 13일
QDHE_img(i,j) = map(1 + int16(WAAD_img(i,j)));

추가 답변 (1개)

DHIVYA BHARKAVI
DHIVYA BHARKAVI 2017년 12월 19일
Sir, Please help to my project your Quandrant Dynamic histogram Equalization in Version Matlab 2013a
  댓글 수: 1
DGM
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 CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by