[Scilab-users] ?= creating ROI from mouse click

Philipp Mühlmann p.muehlmann at gmail.com
Sat Mar 12 13:20:42 CET 2016


@ Samuel,

thanks for the link.

This is a nice function and it is doing what I am searching for.

My example is rather slow though and I don't think that it is handy if one
deals with big 2D Arrays.

For a 640 x 512 array it took me 55 seconds to get the mask.

guess the two for loops are the reason.

clc;tic()
img = rand(512,614).*255;
rows = size(img,'r');cols = size(img,'c');
mask = zeros(img);xpol = [];ypol = [];ibutton = 3;nr_points = 0;
f=figure();f.color_map=graycolormap(255);Matplot(img);
while ibutton == 3;
    [ibutton,xcoord,ycoord]=xclick();
    if ibutton ==3
        nr_points = nr_points + 1;
        plot(xcoord,ycoord,'o');
        xpol(nr_points) = xcoord;
        ypol(nr_points) = rows-ycoord;
    end;enddelete(gcf());
for i = 1:rows;
    for j = 1:cols
        inside = point_in_polygon(xpol, ypol, j, i) ;
        if inside == %t;
            mask(i,j) = 1;
        end;
    endend
f = figure();f.color_map=graycolormap(255);Matplot(img.*mask);plot(xpol,rows-ypol,'o');
t = toc()disp(t);








2016-03-12 1:02 GMT+01:00 Samuel Gougeon <sgougeon at free.fr>:

> Le 12/03/2016 00:42, Samuel Gougeon a écrit :
>
> .../...
>
> This ends the selection part.
>
> After that, identifying points of your grayplot area being in the curve
> may be done with
> point_in_polygon: https://fileexchange.scilab.org/toolboxes/121000
> However, this script is not vectorized. So, if your full area has big
> sizes, it may takes a while.
>
> I would not guaranty that point_in_polygon() can be vectorized, but we may
> try to.
> It does not look too bad, at first sight :)
>
> .
> Actually, its vectorization is straightforward (to process a matrix of
> points without explicit "for" loop,
> instead of a unique point). But the script has other problems.
> Special cases (horizontal segments, points on segments, etc) are not
> really handled.
> Nevertheless, you may give it a try as is. Or improve it for special cases.
>
> Samuel
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
>


-- 
There we have the salad.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160312/1b0f3e86/attachment.htm>


More information about the users mailing list