MATLAB: Set color to imaga with mask

color: blackimage maskingImage Processing Toolboxmasking

I am very new to Matlab and need assistance with the following Problem: I need to set the color of a specific part of an image to black with a given mask. The code I used for creating the following images is written by me. The main problem I'm unable to solve is: the color is not black.
image = imload('huetten.jpg');
image = im2double(image);
image_mark_green = image(:,:,3) >= 0.5;
image_masked = repmat(image,1);
image_masked(~image_mark_green) = double(0); % set to black is missing
The original image is:
The mask created by the code above is:
The resulting image_masked is:
As mentioned above, the image_masked should produce black pixels at the positions determined by the mask. I am really looking forward for any helpful advices!

Best Answer

My_image = imload('huetten.jpg');
My_image = im2double(My_image);
image_mark_green = My_image(:,:,3) >= 0.5;
image_mark_green = repmat(image_mark_green, 1, 1, 3);
image_masked = My_image;
image_masked(~image_mark_green) = double(0);