Hello, with this code I am able to find the centroid of the image i.e. whenever the pupil is at the center. But when pupil is at the corner it is giving centroid on sclera part. so how can i move the centroid according to the pupil. And how to create a sliding window to move it on image to find the max dark area i.e. pupil.
clear all;clc;
Ia = imread('eye.jpg');
subplot(121);imshow(Ia);
bw = im2bw(Ia, graythresh(getimage));
figure, imshow(bw);
% Thresholding
Ia_black = uint8(Ia(:,:,1)<20 & Ia(:,:,2)>200 & Ia(:,:,3)<20);
% Centroid
[y1,x1] = find(Ia_black==0);
x1 = round(mean(x1));
y1 = round(mean(y1));
figure;
imshow(Ia); hold on;
alpha(.5);
plot(x1,y1,'r*');