The last problems were in the function conditional_removal and in creating the randn_logical_matrix.
Matlab docs of randn says
RN = distributed.randn(..., classname) specifies the class of the
distributed array D. Valid choices are the same as for the regular
randn function: 'double' (the default), 'single', 'int8', 'uint8',
'int16', 'uint16', 'int32', 'uint32', 'int64', and 'uint64'.
So this suggests me that it is not supported directly by the existing functions.
So my attempt to make the this logical random number generator and applying the function through a mask
clear;
close all;
image = imread('contour.png');
load('mask_1.mat');
areaLazyRemoval = BW;
image = image(:,:,1);
image = conditional_removal(image, areaLazyRemoval);
image = double(image);
contour(image);
colorbar;
caxis([-2,1.5].*10^7);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function matrix = make_random_logical_matrix(matrix)
[row_max,column_max] = size(matrix);
matrix = randn(row_max,column_max);
for row = 1:row_max
for column = 1:column_max
t = randn;
if t >= 0
matrix(row,column) = 0;
end
if t < 0
matrix(row,column) = 1;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ image ] = conditional_removal( image, areaLazyRemoval )
random_logical_matrix = make_random_logical_matrix(areaLazyRemoval);
areaLazyRemoval = areaLazyRemoval .* random_logical_matrix;
areaLazyRemoval = uint8(areaLazyRemoval);
image = image(:,:,1) .* areaLazyRemoval;
end
and the contour
and the mesh
which seems to be ok solution.
To improve, I think the norm of the situation should be calculated and then the conditional_removal algorithm improved accordingly.