I am getting an error index must be a positive integer or logical. Please Help
2 views (last 30 days)
Show older comments
Mohammed Farhan
on 24 Jan 2014
Commented: Image Analyst
on 5 Feb 2014
Actually I am doing a project on "automatic detection of diabetic retinopathy using digital non dilated rgb fundus images"
my complete code is:-
clc;
clear all;
close all;
%seperating the RED GREEN BLUE components of a rgb image
X=imread('C:\MJCET\91280612.jpg');
imshow(X)
R = X(:,:,1);
image(R), colormap([[0:1/255:1]', zeros(256,1), zeros(256,1)]), colorbar;
%Green Component
G = X(:,:,2);
figure;
image(G), colormap([zeros(256,1),[0:1/255:1]', zeros(256,1)]), colorbar;
%Blue component
B = X(:,:,3);
figure;
image(B), colormap([zeros(256,1), zeros(256,1), [0:1/255:1]']), colorbar;
Z=im2double(G);
%converting GREEN SCALE image to GRAY SCALE image
gray = 0.5870 * X(:,:,2);
figure,imshow(gray);
Y=im2double(gray);
%Median Filtering
A=im2double(Y);
H=medfilt2(A, [30 30]);
figure,imshow(H);
L=im2double(H);
%Normalisation
zz = imsubtract(L,Z);
figure,imshow(zz),title('norm');
%Histogram Equalisation
%%HISTOGRAM EQULAIZER
figure,subplot(1,2,1),imshow(zz), title('original image')
subplot(1,2,2),imhist(zz),title('original image histogram')
%%Calculating the CDF
hst=imhist(zz);
j=1;
cdff(1,1)=hst(1,1);
for i=2:256
cdff(i)=hst(i)+cdff(i-j);
end
cdff1=cdff';
cdf_min=min(cdff);
[row col]=size(zz);
mn=row*col;
figure, plot(cdff), title('CDF of Image')
%%calcuting new intensity
for indx=1:length(cdff)
h(indx)=round((cdff(indx)-cdf_min)/(mn-cdf_min)*255);
end
h1=h';
figure,plot(h1), title('New value for General Histogram')
%%EQULIZED IMAGE
HIm=double(zeros(size(zz,1),size(zz,2)));
for i=1:row;
for j=1:col;
HIm(i,j) = h((round(zz(i,j)+1)));
end
end
figure,subplot(1,2,1),imshow(HIm), title('Equlized Image')
subplot(1,2,2),imhist(HIm) ,title('Equlized image histogram')
Alhamdulillah! except the last part where the histogram is being equalized rest of the program have no error's.
so at last zz comes to be the subtracted image. this image comes when the gray image is subtracted from green plane of rgb fundus image. so I hope the output is also gray image.
I am new to matlab. please help me with errors
output is:
??? Attempted to access h(0); index must be a positive integer or logical.
Error in ==> burr at 74
HIm(i,j) = h((round(zz(i,j)+1)));
>>
1 Comment
Accepted Answer
Image Analyst
on 24 Jan 2014
Evidently zz is not a grayscale image - it's a floating point image because one value of it is (0.945098 - 1). And you can't have the 0.945098'th element of h. It must be 1, 2, 3, etc. - whole numbers greater than or equal to 1, or true false values (a logical vector).
12 Comments
Image Analyst
on 5 Feb 2014
Check the release notes over the past 3 years to see if it was introduced since then. http://www.mathworks.com/help/relnotes/index.html
More Answers (1)
Walter Roberson
on 24 Jan 2014
You have not defined "h". Is it an array or a function?
3 Comments
Walter Roberson
on 25 Jan 2014
You have two images in the range 0 to 1. You subtract one from the other. The maximum possible output for any location is 1 (if the first image had 1 and the second had 0) and the minimum is -1 (if the first image had 0 and the second had 1). So your zz values are in the range -1 to +1. You add 1 to this value, getting a result in the range +0 to +2. You then round that, which is going to give you 0, 1, or 2. You then attempt to use that as an index. The 1 and 2 are plausible indexes but the 0 is not.
I suspect that when you constructed your logic you forgot the subtraction could end up negative.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!