gusucode.com > Diabetic retinopathy > FundsImages.m

    function varargout = FundsImages(varargin)
% FUNDSIMAGES MATLAB code for FundsImages.fig
%      FUNDSIMAGES, by itself, creates a new FUNDSIMAGES or raises the existing
%      singleton*.
%
%      H = FUNDSIMAGES returns the handle to a new FUNDSIMAGES or the handle to
%      the existing singleton*.
%
%      FUNDSIMAGES('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FUNDSIMAGES.M with the given input arguments.
%
%      FUNDSIMAGES('Property','Value',...) creates a new FUNDSIMAGES or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before FundsImages_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to FundsImages_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help FundsImages

% Last Modified by GUIDE v2.5 23-Jul-2019 01:30:47

% Begin initialization code - DO NOT EDIT
global ma;
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FundsImages_OpeningFcn, ...
                   'gui_OutputFcn',  @FundsImages_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before FundsImages is made visible.
function FundsImages_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to FundsImages (see VARARGIN)

% Choose default command line output for FundsImages
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes FundsImages wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = FundsImages_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in loadimage.
function loadimage_Callback(hObject, eventdata, handles)
% hObject    handle to loadimage (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global fname;
[fn pn] = uigetfile('*.jpg','*.png','Select Image File');
complete = strcat(pn,fn);
fname = complete;
set(handles.inputtxt,'string',complete);
pic1=imread (complete);
imshow(pic1,'Parent',handles.inputimg);
title(handles.inputimg,'Fundus Images');



function inputtxt_Callback(hObject, eventdata, handles)
% hObject    handle to inputtxt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of inputtxt as text
%        str2double(get(hObject,'String')) returns contents of inputtxt as a double


% --- Executes during object creation, after setting all properties.
function inputtxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to inputtxt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in edge.
function edge_Callback(hObject, eventdata, handles)
% hObject    handle to edge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pa = get(handles.inputtxt,'String');
A=imread(pa);
B=rgb2gray(A);
C=double(B);
for i=1:size(C,1)-2
    for j=1:size(C,2)-2
        %Sobel mask for x-direction:
        Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
        %Sobel mask for y-direction:
        Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
       
        %The gradient of the image
        %B(i,j)=abs(Gx)+abs(Gy);
        B(i,j)=sqrt(Gx.^2+Gy.^2);
       
    end
end
Thresh=10;
B=max(B,Thresh);
B(B==round(Thresh))=0;

B=uint8(B);
imshow(~B);


% --- Executes on button press in pprocess.
function pprocess_Callback(hObject, eventdata, handles)
% hObject    handle to pprocess (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% check image
pa = get(handles.inputtxt,'String');
im=imread(pa);
te = rgb2gray(im);
imshow(te);



function bw=adaptivethreshold(IM,ws,C,tm)
%ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the
%foreground from the background with nonuniform illumination.
%  bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local 
%   threshold mean-C or median-C to the image IM.
%  ws is the local window size.
%  tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median.
%
%  Contributed by Guanglei Xiong (xgl99@mails.tsinghua.edu.cn)
%  at Tsinghua University, Beijing, China.
%
%  For more information, please see
%  http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm

if (nargin<3)
    error('You must provide the image IM, the window size ws, and C.');
elseif (nargin==3)
    tm=0;
elseif (tm~=0 && tm~=1)
    error('tm must be 0 or 1.');
end

IM=mat2gray(IM);

if tm==0
    mIM=imfilter(IM,fspecial('average',ws),'replicate');
else
    mIM=medfilt2(IM,[ws ws]);
end
sIM=mIM-IM-C;
bw=im2bw(sIM,0);
bw=imcomplement(bw);


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Segmentation
pa = get(handles.inputtxt,'String');
im = imread(pa);
k =100;
img_hist = zeros(256,1);
hist_value = zeros(256,1);

for i=1:256
	img_hist(i)=sum(sum(im==(i-1)));
end;
for i=1:256
	hist_value(i)=i-1;
end;
%cluster initialization
cluster = zeros(k,1);
cluster_count = zeros(k,1);
for i=1:k
	cluster(i)=uint8(rand*255);
end;

old = zeros(k,1);
while (sum(sum(abs(old-cluster))) >k)
	old = cluster;
	closest_cluster = zeros(256,1);
	min_distance = uint8(zeros(256,1));
	min_distance = abs(hist_value-cluster(1));

	%calculate the minimum distance to a cluster
	for i=2:k
		min_distance =min(min_distance,  abs(hist_value-cluster(i)));
	end;

	%calculate the closest cluster
	for i=1:k
		closest_cluster(min_distance==(abs(hist_value-cluster(i)))) = i;
	end;

	%calculate the cluster count
	for i=1:k
		cluster_count(i) = sum(img_hist .*(closest_cluster==i));
	end;


	for i=1:k
		if (cluster_count(i) == 0)
			cluster(i) = uint8(rand*255);
		else
			cluster(i) = uint8(sum(img_hist(closest_cluster==i).*hist_value(closest_cluster==i))/cluster_count(i));
        end;
	end;
	
end;
imresult=uint8(zeros(size(im)));
for i=1:256
	imresult(im==(i-1))=cluster(closest_cluster(i));
end;

clustersresult=uint8(zeros(size(im)));
for i=1:256
	clustersresult(im==(i-1))=closest_cluster(i);
end;

imshow(imresult);


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pa = get(handles.inputtxt,'String');
I = imread(pa);
J = imadjust(I,stretchlim(I),[]);
t = rgb2gray(J);
imshow(t);


% --- Executes on button press in pointint.
function pointint_Callback(hObject, eventdata, handles)
% hObject    handle to pointint (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

pa = get(handles.inputtxt,'String');
img1=imread(pa);
img1=rgb2gray(img1);
img2=im2bw(img1,graythresh(img1));
img2=~img2;
B = bwboundaries(img2);
img3=imread(pa);
imshow(img3)
hold on
length(B)

len =0;
for k = 1:length(B)
  boundary = B{k};
  len(k) = length(boundary);
end

a = max(len);
   Y = len(len ~= a);
   b = max(Y);
for k = 1:length(B)
  boundary = B{k};
  if(b ==length(boundary) || a ==length(boundary))
      plot(boundary(:,2), boundary(:,1), '--w', 'LineWidth', 0.2)
  end
end



% --- Executes on button press in motionpattern.
function motionpattern_Callback(hObject, eventdata, handles)
% hObject    handle to motionpattern (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global fname;
global image_enhance;
temp = fname;
pa = get(handles.inputtxt,'String');
fname =pa;

method_set={'AR','MCE','MCEDRC','TW-CES','DRC-CES','SF-CES','TW-CES-BLK','DRC-CES-BLK','SF-CES-BLK'}; 
[mr mc]=size(method_set);
jpqm=zeros(1,mc);
cef=zeros(1,mc);
image='image18';
lamda=1.95;      
alpha=0.98;   
gamma_JM=1.95;  
pivotx=0.5;
pivoty=0.5;
power1=1.8;
power2=0.8;
gamma=1.95; 
 thresh1=0.10;
 thresh2=gamma;

betaDC=1.0; 
sigma_thresh=15;
nIteration=1; 
 fsave=1; 
 

  org_I	 = imread(pa);
  
 [height width depth]=size(org_I);
 CI_ycbcr=RGB_YCbCr(org_I);
 Y=CI_ycbcr(:,:,1);
 maxDC=double(max(max(Y)));
 Cb=CI_ycbcr(:,:,2);
 Cr=CI_ycbcr(:,:,3);

    dct_Y=blkproc(Y,[8,8],@dct2);
    dct_Cb=blkproc(Cb,[8 8],@dct2);
    dct_Cr=blkproc(Cr,[8 8],@dct2);
     org_dct_CI_ycbcr(:,:,1)=dct_Y;
     org_dct_CI_ycbcr(:,:,2)=dct_Cb;
     org_dct_CI_ycbcr(:,:,3)=dct_Cr;
     
 
  %M is the index for method
M = 4;
 
dct_CI_ycbcr=org_dct_CI_ycbcr;
 
 method=char(method_set(M));
 
 sprintf('Using %s',char(method))   
 ofname=['result/'  sprintf(image) '_' sprintf(method)];

%      sprintf('Output file= %s ',ofname)
      for i=1:nIteration

   gamma_ret=ones(height/8+2,width/8+2);  
   for l=1:height/8+2
    for m=1:width/8+2
        gamma_ret(l+1,m+1)=gamma;
    end
   end
          
    for l=0:height/8-1
    for m=0:width/8-1
        
   
       Z=enhance_composite_dc_sigma(dct_CI_ycbcr(l*8+1:l*8+8,m*8+1:m*8+8,:),betaDC,maxDC,1);
          
           
       enh_dct_Ycbcr(l*8+1:l*8+8,m*8+1:m*8+8,:)=Z;
    end
    end
    
    dct_CI_ycbcr=enh_dct_Ycbcr;
      end  
    
    enh_Y=blkproc(enh_dct_Ycbcr(:,:,1),[8,8],@idct2);
    enh_Cb=blkproc(enh_dct_Ycbcr(:,:,2),[8,8],@idct2);
    enh_Cr=blkproc(enh_dct_Ycbcr(:,:,3),[8,8],@idct2);   
     Y=enh_Y;
     Cb=enh_Cb;
     Cr=enh_Cr;
    
     jpqm(M)=jpeg_quality_score(uint8(Y));
      
    
    [h w]=size(enh_Y);
   
    [h w]=size(enh_Cb);
   
    [h w]=size(enh_Cr);
  
    
    enh_CI=zeros(h,w,3);
    enh_CI(:,:,1)=enh_Y(1:h,1:w);
    enh_CI(:,:,2)=enh_Cb(1:h,1:w);
    enh_CI(:,:,3)=enh_Cr(1:h,1:w);
    out=YCbCr_RGB(enh_CI);
    cef(M)=colourfulness_metric(uint8(out))/colourfulness_metric(uint8(org_I));        

  I = rgb2gray(uint8(out));

  image_enhance = I;
  Threshold = 10;
  bloodVessels = VesselExtract(image_enhance, Threshold);
% figure;
% subplot(121);imshow(image_enhance);title('Input Image');


vessel=im2uint8(bloodVessels);
bw = bwareaopen(vessel,10);

se=strel('disk',4);                                                 % morphological dilation with structural element disk with dia 4
a=imdilate(bw,se);


bw=imresize(a,[400,400])



pa = get(handles.inputtxt,'String');
image = imread(pa);

image1=image(:,:,2);
image1=imresize(image1,[400,400]);% copying G image to process further, using this 3d to 2d

image4=im2bw(image1);



b=imsubtract(bw,image4);



c=imresize(b,[400,400]);




d=imresize(a,[400,400]);
d=im2uint8(d);

[lab num]=bwlabel(d);                                          % making labels for all extracted objects
areas=[];           
for i=1:num                                                         % concluding centroids for all extracted objects
    dummy=lab==i;
    [r c]=find(dummy==1);
    areas(i,1)=i;
    areas(i,2)=round(mean(r)); 
    areas(i,3)=round(mean(c));
end

areas=sortrows(areas,3);                                            % sorting all elements according to there areas
od_loco=[areas(1,2) areas(1,3)];

od_bw=lab==areas(1,1);   % extracting Bw OD part
d = uint8(d);
image_od=d.* uint8(od_bw);

image_od=im2uint8(image_od);
image_od1=imresize(image_od,[400,400]);
d=imresize(d,[400,400]);
e=imsubtract(d,image_od1);

h=imresize(e,[400,400]);
setappdata(0,'evalue1',h);

vessel = imresize(vessel,[400,400]);

ma = imsubtract(vessel,h);


%ilam coe start%


image=imresize(org_I,[400,400]);
image=im2uint8(image);
image1=image(:,:,2);
image1=imresize(image1,[400,400]);% copying G image to process further, using this 3d to 2d
[M,N] = size(image1);
sa = 2.0;
rt = mim(image1,sa);

[tt1,e1,cmtx] = myThreshold(rt);
ms = 45;    
mk = msk(image1,ms);

rt2 = 255*ones(M,N);
for i=1:M
    for j=1:N
        if rt(i,j)>=tt1 & mk(i,j)==255
            rt2(i,j)=0;
        end
    end
end
J = im2bw(rt2); 

J= ~J;
[Label,Num] = bwlabel(J);
Lmtx = zeros(Num+1,1);
for i=1:M
    for j=1:N
        Lmtx(double(Label(i,j))+1) = Lmtx(double(Label(i,j))+1) + 1;
    end
end
sLmtx = sort(Lmtx);
cp = 950;
for i=1:M
    for j=1:N
        if (Lmtx(double(Label(i,j)+1)) > cp) & (Lmtx(double(Label(i,j)+1)) ~= sLmtx(Num+1,1))
            J(i,j) = 0;
        else
            J(i,j) = 1;
        end
    end
end
for i=1:M
    for j=1:N
        if mk(i,j)==0
            J(i,j)=1;
        end
    end
end


vessels=imresize(~J,[400,400]);
vessel=im2uint8(vessels);
bw = bwareaopen(vessel,10);

image2=imresize(image1,[400,400]);
image4=im2bw(image1);
b=imsubtract(image4,bw);
c=imresize(b,[400,400]);
image_dummy =c;

%ilam coe ends %



se=strel('disk',4);                                                 % morphological dilation with structural element disk with dia 4
a=imdilate(c,se);

d=imresize(a,[400,400]);
d=im2uint8(d);
imwrite(d,'dilate.jpg','quality',50);

% image_dummy =d;
% subplot(4,4,6)
% imshow(image_dummy);
% title('joining close objects together');

[lab num]=bwlabel(d);                                          % making labels for all extracted objects
areas=[];           
for i=1:num                                                         % concluding centroids for all extracted objects
    dummy=lab==i;
    [r c]=find(dummy==1);
    areas(i,1)=i;
    areas(i,2)=round(mean(r)); 
    areas(i,3)=round(mean(c));
end

areas=sortrows(areas,3);                                            % sorting all elements according to there areas
od_loco=[areas(1,2) areas(1,3)];

image_od_c=image;                                                   % making cross lines about OD position
image_od_c(od_loco(1)-2:od_loco(1),:,1:2)=0;
image_od_c(od_loco(1)-2:od_loco(1),:,3)=255;
image_od_c(:,od_loco(2)-2:od_loco(2),1:2)=0;
image_od_c(:,od_loco(2)-2:od_loco(2),3)=255;

image_od_c=imresize(image_od_c,[400,400]);
imwrite(image_od_c,'OD.jpg','quality',50);

% image_dummy =image_od_c;
% subplot(4,4,7)
% imshow(image_dummy)
% title('OD position located');



od_bw=lab==areas(1,1);   % extracting Bw OD part
d = uint8(d);
image_od=d.* uint8(od_bw);
imwrite(image_od,'OD1.jpg','quality',50);

% image_dummy =image_od;
% subplot(4,4,8)
% imshow(image_dummy);
% title('extracted OD bw');


image_od=im2uint8(image_od);
image_od1=imresize(image_od,[400,400]);
d=imresize(d,[400,400]);
e=imsubtract(d,image_od1);

h=imresize(e,[400,400]);
imwrite(h,'lesions.jpg','quality',50);

% image_dummy =h;
% subplot(4,4,9)
% imshow(image_dummy);
% title('neglected OD for G image')


lesions_bw=e & (~image_od1); 
lesions_bw=imresize(lesions_bw,[400,400]);
image_f=imresize(image,[400,400]);% taking position values for features 
[r c]=find(lesions_bw==1);
for i=1:length(r)                                                   % applying blue color for detected feature in maing RGB image
    image_f(r(i),c(i),1:2)=0;
    image_f(r(i),c(i),3)=255;
end

% image_dummy =image_f;
% subplot(4,4,10)
% imshow(image_dummy)
% title('predicted feature')
imwrite(image_f,'last.jpg','quality',50);

[y1,x1,z1] = size(org_I);
final=imresize(image_f,[y1,x1]);
imshow(final)

% pic = image_enhance;
%      black = 0;
%     white = 0;
%     X=0;
%     cnt = 1;
%     for mm = 1:size(pic,1)
%     for nn = 1:size(pic,2)
%           a = pic(mm,nn,1);
%           if(a > 0 && a < 150)
%               black = black + 1;
%               pic(mm,nn, :) = a;
%           elseif(a < 220)    
%               pic(mm,nn, :) = 120;
%           else
%               white = white + 1;
%               pic(mm,nn, :) = 255;
%               X(cnt,1) = nn;
%               X(cnt,2) = mm;
%               cnt = cnt + 1;
%           end
%           
%     end    
%     end
%     
%     figure;
%     imshow(image_enhance)
%     title('Medial Axis Detection')
%     opts = statset('Display','final');
% [idx,ctrs] = kmeans(X,1,...
%                     'Distance','city',...
%                     'Replicates',5,...
%                     'Options',opts);
%               %555  plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
% hold on
% plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)
% plot(ctrs(:,1),ctrs(:,2),'kx',...
%      'MarkerSize',12,'LineWidth',2)
%  hold off;
% ctrs(:,1)
% ctrs(:,2)
% 
% figure;
% imshow(image_enhance)
% hold on;
% %rectangle('Position',[ctrs(:,1)-40, ctrs(:,2)-40, 100, 100 ],'EdgeColor','g','LineWidth',2)
%   rectangle('Position',[ctrs(:,1)-40, ctrs(:,2)-40, 100, 100 ],'Curvature',[1,1],...
%    'FaceColor','k')
%  title('Fitted Area');
%  hold off
%  
 
     
       %sshold off;
 
 
%   figure;
%        I2 = imcrop(image_enhance,[ctrs(:,1)-40, ctrs(:,2)-40, 100, 100]); 
%       I2 = imresize(I2,[100 100]);
%         
%        imshow(I2);
%        hold on;
% %       rectangle('Position',[x11-30, y11+20, x12 - x11 + 10, (y12 - y11) + 10],'Curvature',[1,1],...
% %           'FaceColor','r')
% %        title('Optic Disc Vessels')
%  hold off;
% 
%        
%       f= figure('visible','off'), imshow(image_enhance, 'Border', 'tight');
%  rectangle('Position',[ctrs(:,1)-40, ctrs(:,2)-40, 100, 100],'Curvature',[1,1],...
%            'FaceColor','r')
%        imshow(image_enhance)



% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pa = get(handles.inputtxt,'String');
RGB=imread(pa);
j = rgb2gray(RGB);
imshow(j)

ratio=[];

j=imresize(j,[576,768]);

var=0;for i=1:576
    for k=1:768
        if(j(i,k)<=1) var=var+1; end; end; end;


imshow(j)


bw=roicolor(j,150,255);



k=roicolor(j,0,255);
total=bwarea(k)-var;

total

w = sum(bw);
u = sum(bw');
[C,I] = max(w);
[c,J] = max(u);
p=bw;
blnkud=round(2*C/3);
blnklr=round(2*c/3);
for ii=(I-blnkud):(I+blnkud)
    for jj=(J-blnklr):(J+blnklr)
        p(jj,ii)=0;
    end
end
for po=6:570
    for mo=6:762
        if(j(po,mo)<=1)
            p(po,(mo+5))=0;
            p(po,(mo-5))=0;
            p((po+5),mo)=0;
            p((po-5),mo)=0;
        end;
    end; end;



test=bwarea(p);
estimate=test/total;


count=0
HSV=rgb2hsv(RGB);H=HSV(:,:,1);

theta = -pi:0.01:pi;
for r=90:4:130
    x=round(J+r*cos(theta));
    y=round(I+r*sin(theta));
   
    
    q=j;
    chu=RGB;

    for b=1:629
        n=0;
        while(x(1,b)<566 & y(1,b)<758 & x(1,b)>10 & y(1,b)>10 & n==0)
            g(1,b)= 1000*H(x(1,b),y(1,b));
            q(x(1,b),y(1,b))=255;
            chu(x(1,b),y(1,b),:)=0;
            if g(1,b)<105
                arr(1,b)=1;

            else
                arr(1,b)=0;
            end
            n=n+1;
        end
    end
    
    
    imshow(chu);

    
    h=[x' y' zeros(629,1) arr'];
    
    
    m=0;
    for b=629:-1:1
        if(arr(1,b)==1)
            m=m+1;
        elseif(m~=0)
            h(b+1,3)=m;
            m=0;
    
        end
    end
    
    [val1,pos1]=max(h(:,3));
    h(pos1,3)=0;
    [val2,pos2]=max(h(:,3));
    ratio1=val1/val2;
    if ratio1<3
        count=count+1;
        ratio=[ratio ; ratio1];
    end
end
        
problem=1.1682*sum(ratio)/count
estimate=estimate*10^6

if(problem<=1.6)
    f1=0;
elseif(problem<=2)
    f1=1;
else f1=2;
end;
if(estimate>5*10^3)
    f2=2;
elseif(estimate>10^3)
    f2=1;
else
    f2=0;
end;

if(f1==2 & f2==2)
    disp('Person has Severe diabetic retinopathy - Stage 8');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Person has Severe diabetic retinopathy - Stage 8\n',problem,estimate);
elseif(f1==2 & f2==1)
    disp('Eye in Stage 7');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 7\n',problem,estimate);
elseif(f1==1 & f2==2)
    disp('Eye in Stage 6');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 6\n',problem,estimate);
elseif(f1==2 & f2==0)
    disp('Eye in Stage 5');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 5\n',problem,estimate);
elseif(f1==1 & f2==1)
    disp('Eye in Stage 4');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 4\n',problem,estimate);
elseif(f1==0 & f2==2)
    disp('Eye in Stage 3');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 3\n',problem,estimate);
elseif(f1==1 & f2==0)
    disp('Eye in Stage 2');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 2\n',problem,estimate);
elseif(f1==0 & f2==1)
    disp('Eye in Stage 1');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Eye in Stage 1\n',problem,estimate);
else
    disp('Normal eye');
    str=sprintf('\n     Ratio of Vessels : %f \n\n     Estimated area of cotton wool spots : %f \n\n     Normal eye \n',problem,estimate);
end;

msgbox(str,'RESULT');