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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…