from Region of Interest analysis by Florence Kussener
This example has been developed to add capabilities in ROI analysis: add, delete, change location,

Region of interest tool

Region of interest tool

the goal of this GUI is to be able to create mask, and modify it after. We allow the following modifications:

 * Translate the mask
 * Change points location
 * Add points
 * Remove Points

Simple statistical analysis can be done on the ROI defined by the user.

In this example, I use Image Processing for ROI creation. The other steps use array manipulation from MATLAB.

Contents

clc, clear all,close all,

Load data

We works on coins.png image

I=imread('coins.png');
I(:,:,1)=I;
I(:,:,2)=I;
I(:,:,3)=I(:,:,1);
imshow(I)

Mask creation.

We use ROIPOLY function to create the Mask

[Mask,xi,yi]=roipoly;
I(:,:,3)=255*Mask;
imshow(I)

Mask translation

In this step, we translate the mask. The user give an initial point and a destination point.

[x,y]=ginput(2);
dx=round(x(2)-x(1));
dy=round(y(2)-y(1));
[m,n]=size(Mask);
if dx>0
    Mask=[zeros(m,dx+1) Mask];
    Mask(:,end-dx:end)=[];
else
    Mask(:,1:-dx)=[];
    Mask(:,end:end-dx)=0;
end
if dy<0
    Mask(1:-dy,:)=[];
    Mask(end:end-dy,:)=0;
else
    Mask(end-dy:end,:)=[];
    Mask=[zeros(dy+1,n);Mask];
end

I(:,:,3)=255*Mask;
imshow(I);
xi=xi+dx;
yi=yi+dy;

Add points

The user click on the location of a new point. The algorithm test the best location of a point considering the distance with the other points.

[x,y]=ginput(1);

[m,ind]=min(sqrt((xi-x).*(xi-x)+(yi-y).*(yi-y)));
xi1=[xi(1:ind) ;x ;xi(ind+1:end)];
yi1=[yi(1:ind); y; yi(ind+1:end)];
xi2=[xi(1:ind-1) ;x ;xi(ind:end)];
yi2=[yi(1:ind-1); y; yi(ind:end)];

d1=sum(sqrt((xi1(1:end)-[xi1(2:end);xi1(1)]).^2+(yi1(1:end)-[yi1(2:end);yi1(1)]).^2));
d2=sum(sqrt((xi2(1:end)-[xi2(2:end);xi1(1)]).^2+(yi2(1:end)-[yi2(2:end);yi2(1)]).^2));
if d1>d2
    xi=xi2;yi=yi2;
else
    xi=xi1;yi=yi1;
end
Mask=roipoly(I,xi,yi);

I(:,:,3)=255*Mask;

imshow(I)

Change points location

The user click on the location of the "bad" point. This points is located with a red circle. A second click gives the new location of the point

[x,y]=ginput(1);

[m,ind]=min(sqrt((xi-x).*(xi-x)+(yi-y).*(yi-y)));
hold on
plot(xi(ind),yi(ind),'ro')
hold off
[xp,yp]=ginput(1);
xi(ind)=xp;
yi(ind)=yp;

[Mask,xj,yj]=roipoly(I,xi,yi);
I(:,:,3)=255*Mask;
imshow(I)

Remove points

In this step, the user can remove points by selecting it.

[x,y]=ginput(1);
[m,ind]=min(sqrt((xi-x).*(xi-x)+(yi-y).*(yi-y)));
xi(ind)=[];
yi(ind)=[];
[Mask,xj,yj]=roipoly(I,xi,yi);
I(:,:,3)=255*Mask;
imshow(I)

Statistical analysis

We do a statistical analysis on the ROI specified above.

M=I(:,:,1);
M=M(Mask);
moyenne=mean(M(:));
maximum=max(M(:));
minimum=min(M(:));

disp(['Max=' num2str(maximum)]);
disp(['Mean=' num2str(moyenne)]);
disp(['Min=' num2str(minimum)]);
Max=255
Mean=209.9265
Min=69

All the step are defined in the GUI

The ROItool GUI contains all the step. ROItool

Contact us at files@mathworks.com