Number of pixels while modifying freehand on a figure

조회 수: 2 (최근 30일)
Nikan Fakhari
Nikan Fakhari 2021년 8월 2일
편집: DGM 2021년 8월 3일
Hi there,
Is there a way so matlab contniously display the number of the pixels within ROI as Im modyfing the shape (shape of freehand) object on a figure?
So for example I displayed a freehand object on my matlab figure, now I want to modify the shape using the WayPoints, tho while Im modifying I need to khow much my number of pixels within the ROI changes.
I would really appreciate it, if you can help me with this issue.
Thank you.
Nikan

답변 (1개)

DGM
DGM 2021년 8월 3일
편집: DGM 2021년 8월 3일
Here is a very simple example
inpict = imread('cameraman.tif');
% show image and make ROI
imshow(inpict);
R = drawfreehand(gca);
% specify CBF to be executed when ROI is moved
addlistener(R,'MovingROI',@whenmove);
addlistener(R,'ROIMoved',@whenmove);
% show initial area before manipulation
area = sum(sum(createMask(R)))
% function to be executed whenever ROI or nodes are moved
function whenmove(R,~)
% just dump the area to console
% you can choose to do something fancier
area = sum(sum(createMask(R)))
end
As an example of "something fancier", you might want to tidy up console output a bit. This is a very crude approach, but it's cleaner than dumping everything.
% pad the console so that redraw doesn't back into prior output/warnings
fprintf('\n \n')
% function to be executed whenever ROI or nodes are moved
function whenmove(R,~)
area = sum(sum(createMask(R)));
rpad = sprintf(repmat(sprintf('\b'),[1 19]));
thisnum = sprintf('%d',area);
fprintf([rpad 'Area is ' thisnum repmat(' ',[1 10-numel(thisnum)]) '\n'])
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by