I create a closed region on a picture by impoly('Closed', true)
and lastly after marking the area for the mask BW = createMask(h)
in Matlab commandline.
Initial commands before marking points for the mask in the figure
imshow('contour.png');
h = impoly('Closed',true);
Here, I used nkjt's answer below. The picture to be filtered by the function conditionalRemoval(image, area)
Then, I run
image = imread('contour.png');
areaLazyRemoval = BW;
image = conditional_removal(image, areaLazyRemoval);
I now have the mask and the picture. I should apply the function conditional_removal to them.
How can you use this mask now and apply the function to it in the its marked region?
My function conditional_removal's pseudocode is
function [ image ] = conditional_removal( image, areaLazyRemoval )
% dim image 794 x 1001 x 3 uint
% dim areaLazyRemoval 794 x 1001 logical
image(:,:,1) .* areaLazyRemoval; % TODO wrong operator here!
% all pixels marked by logical ones in areaLazyRemoval should get lazyRemoval applied
% else greedyRemoval so zero
%
end
%%%%%%%%%%%%%%%%%%%%%%%
% lazy removal function
% so remove by 50% chance the thing
function pixel = lazyRemoval(pixel)
if randn > 0
pixel = 0;
end
% TODO how to apply pixel-wise removal to the logical matrix and image?
How can you apply the pixel-wise removal to the image by the logical matrix, mask?
By this:
impoly > Generate Data > function createfigure1
Do you mean after calling impoly, you go into the figure window and select "Generate Code"? Which will create a function createfigure
- but this has nothing to do with impoly
.
There are a couple of ways you can extract the ROI.
After choosing the area with impoly
, before closing the figure:
BW = createMask(h);
Or you can extract the position with getPosition
and then use roipoly
.