[Scilab-users] ?= creating ROI from mouse click
Philipp Mühlmann
p.muehlmann at gmail.com
Fri Mar 11 11:01:10 CET 2016
...so to better explain my purpose:
Assumptions:
- one has a 2D Array of data or a gray scale Image
- one wants to select the Region of interest via mouse clicks, by clicking
into the Image
- the ROI can be of any shape (triangle, rectangle, parallelogram, 5-point
star ...etc)
- one wants to Display only the ROI...everything outside of the ROI should
be set to 0
purpose of ROI
- one wants to process only a part of the input Image in such a way that:
-if Pixel belongs to ROI than process Image
- if Pixel does not belong to ROI do nothing
So since I somehow can't figure it out how to:
- calculate by hand if a pixel is left, right, above or below a line
defined by two points (to bad, i know)
and therfore
- sort pixels in such a way that they either belong to the ROI or not
I use the mentioned approach.
Here the code:
function [ROI, ROIpoints]=RoiImage(img);
cols = size(img,'c');
rows = size(img,'r');
f = figure();
ShowImage(im,'click with mouse into image'); // use of IDP
function, could be exchanged by Matplot()
a = gca();
a.margins = [0 0 0 0];
messagebox(["left click into the image to get ROI borders";"end
with any other button"], "Information", "info", ["OK"])
ibutton = 3;
nr_points = 0;
while ibutton == 3;
[ibutton,xcoord,ycoord]=xclick();
if ibutton == 3 then
nr_points = nr_points + 1
plot(xcoord, ycoord,'o');
ROIpoints(nr_points,:) = double([xcoord ycoord]);
end
end
nr_points = max(size(ROIpoints));
if nr_points < 3 then
mprintf('not enough points \n');
mprintf('ROI requires minimal 3 points \n');
ROI = 0;
return;
end;
f = figure();
f.background = 8;
f.axes_size = [cols,rows];
x=ROIpoints(:,1);
y=ROIpoints(:,2);
xfpolys(x,y,[-1]); // how does xfpolys know which area to
fill? Is this area stored somewhere as a variable?
a=gca();
a.tight_limits = "on";
a.data_bounds=[0,0;cols,rows];
a.margins = [0 0 0 0];
xs2bmp(gcf(),'mask.bmp');
maskIm = RGB2Gray(ReadImage('mask.bmp')); // uses IDP functions
deletefile('mask.bmp');
ROI = zeros(rows,cols);
pos = find(maskIm < 255);
ROI(pos)= 1;
delete();
endfunction
--
There we have the salad.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160311/d1994586/attachment.htm>
More information about the users
mailing list