Draw multiple regions on an image- imfreehand

前端 未结 2 1795
清酒与你
清酒与你 2021-01-20 10:22

I\'d like to manually draw multiple regions on an image to create a binary mask of the drawn regions (ground truth).

I attached the code to do it using imfreehand th

2条回答
  •  佛祖请我去吃肉
    2021-01-20 11:08

    You can loop until you get an empty mask - this will indicate that the user finished drawing all masks.
    Let sz be the desired size of the output mask, then

    totMask = false( sz ); % accumulate all single object masks to this one
    h = imfreehand( gca ); setColor(h,'red');
    position = wait( h );
    BW = createMask( h );
    while sum(BW(:)) > 10 % less than 10 pixels is considered empty mask
          totMask = totMask | BW; % add mask to global mask
          % you might want to consider removing the old imfreehand object:
          delete( h ); % try the effect of this line if it helps you or not.
    
          % ask user for another mask
          h = imfreehand( gca ); setColor(h,'red');
          position = wait( h );
          BW = createMask( h );
    end
    % show the resulting mask
    figure; imshow( totMask ); title('multi-object mask');
    

提交回复
热议问题