Hi Ahmad,
As per my understanding, you want to retain only the area within the white perimeter in the image, while blacking out everything outside of it. Additionally, you want this process to be applied to multiple images with varying skin tones, as long as they have the white perimeter.
To achieve this, you can use MATLAB 'imfill' function. For a detailed workflow please refer to the steps given below:
- Step 1: Read the image using MATLAB 'imread' function.
- Step 2: FInd out all the pixels with pure white value.
- Step 3: You can use image dilation to close small gaps in the perimeter. To achieve this you can use MATLAB 'imdilate' function.
BW_dilated = imdilate(BW, SE);
- Step 4: Fill holes inside the dilated region to ensure all areas inside the boundary are covered, using MATLAB 'imfill' function.
BW_filled = imfill(BW_dilated, 'holes');
- Step 5: Set pixels outside the mask to black.
newImg(repmat(~BW_filled, [1, 1, 3])) = 0;
You can visualize the processed image as shown below.
For more information on MATLAB 'imdilate' and 'imfill' functions, please refer to the documentations linked below.
Hope this solves your query.