Eror when aplaying Masking image to colorfull image

3 views (last 30 days)
mask image and source image size do not match
I got an error like that, what should i do?

Accepted Answer

Shrey Tripathi
Shrey Tripathi on 14 Jun 2023
To help solve this issue, it would be good if you provide some context in terms of what code you have written, where the error is occurring, the images that are being used, and/or the dimensions of the images being used.
Nevertheless, to debug the issue, you can start with checking the size of both images using the size function and make sure they both have the same number of rows and columns.
size(maskImage)
size(sourceImage)
If the sizes don't match, you can either resize the mask image to match the source image or vice versa. For example, to resize the mask image:
resizedMask = imresize(maskImage, [size(sourceImage, 1) size(sourceImage, 2)]);
This will resize the mask image to have the same number of rows and columns as the source image.
Then, apply the mask to the source image using the imoverlay function:
maskedSource = imoverlay(sourceImage, resizedMask, [1 0 0]);
This will apply the mask to the source image and highlight the masked regions with red color.
All of this assumes that the mask is a binary image with 0's and 1's indicating the masked and unmasked regions, respectively. If the mask has more than two values, you may need to convert it to a binary mask using the imbinarize function.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!