How do I fill in reflections with an eye Image?

HI There, I am trying to localize and fill in the reflections within an eye. Below is the function which should Localize the reflections: (Input: eye Image, Output: Eye Image with Localize reflections)
function [eyeClose] = findReflections(eye);
%Since Images are already greyscale, no need to convert them.
%Average Intensity Value of image
iAve = mean2(eye);
%*Maximum Intensity Value of image calculated*%
%Gets the 0.04% of the Total amount of pixels in the image
iMaxS = 300*400*0.04;
%Sort the values in descending order
[sortedValues,sortIndex] = sort(eye(:),'descend');
%Get a linear index into Eye image of the iMaxS largest values
highValues = sortedValues(1:iMaxS);
%Fixed amount of Brighest Pixels averaged
iMaxB = mean(highValues);
%P (fixed proportion) is between 0 to 1
%After trial and error 0.8 seems to gather the best of the reflections in
%the Iris
P = 0.8;
%Intensity Threshold
tRef = iAve + P*(iMaxB-iAve)
indicies = uint8(double(eye <=tRef));
eyeTref = eye.*indicies;
%creates a nonflat, ball-shaped structuring element (actually an ellipsoid)
%whose radius in the X-Y plane is R and whose height is H.
se = strel('ball',5,45);
%Dilation Operator
eyeMorph = imdilate(eyeTref,se);
%Closure Operator
eyeClose = imclose(eyeMorph,se);
I am duplicating an algorithm from a scientific paper called " Reliable Algorithm for Iris Segmentation in eye image" by Wojciech Sankoski. Any help would be greatly appreciated
here is the image of the eye:
%

 Accepted Answer

I don't think that's a good algorithm because it's masking the non-specular-reflection part of the image and doing a dilation and then closing on it. The dilation will "fill in" the holes where the specular reflections were, however it's doing that on the whole image, not just where the reflections were. And the closing is just another dilation followed by an erosion so I don't know what the purpose of that is - it will just destroy the "good" parts of the image even more.
I think what you should do is to use the dilated image to fill in just the masked out parts of the image. This will leave the good parts of the image untouched:
out = eyeImage; % Initialize
out(~indicies) = eyeMorph(~indicies); % Replace specular reflections with dilated.
Notice that I renamed your eye (which is a built-in function) with eyeImage so as to not destroy the built-in image.
Even better would be to just use roifill() which is meant for this kind of thing. The holes in the reflections will be filled in with a weighted average of the surrounding gray levels instead of the max value, which is what imdilate does.

5 Comments

Thank uou! It seems be to correct. Just to clarify, when you say "eyeImage" Do you mean the eyeTref in my code or do you mean the actual input eye at the beginning? and then should I not do the closure operation?
Either one. eyeTref is just eyeImage with the bright spots blackened out. Since we're replacing those with nearby pixels, either one will work.
Awesome thanks. One last thing (i promise) I need to use a closure operation after. This operation is applied to connect reflection areas positioned close to each other.
Would you know how to do this?
You can do it like you had - the syntax looks correct, though I don't know why you need to forge connections between nearby reflections when no reflection is there yet. I mean, wouldn't this just make it worse?
Oh so there isn't a need to use it then because the imdilate fills in the reflections?

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!