how to set specific part of the image to white and remaining part to black in matlab
3 views (last 30 days)
Show older comments
0
I am trying to learn image processing and I just found one question related to my area of interest. I have an image in which there is two things one is mug and the other is thermos. I just want to show the cup in white color for that first i convert the image in graysacle and then I convert with imbinarize. This is my problem statement
Example 1
The original image on the left is given i.e., original.jpg. The middle image (theft 1) shows that mug is stolen from the original image. Now you have to generate the output in such a way that the stolen object i.e., the mug is visible only. The rightmost image shows the stolen object i.e., mug, that is the required output to be generate by your code.
This is an image the kind of output I want

This is the code i have tried
close all
I = imread('Original-min-min.JPG');
gray = rgb2gray(I)
BW = imbinarize(gray);
figure
imshowpair(gray,BW,'montage')
This is the image output i am getting with my code

0 Comments
Answers (1)
Image Analyst
on 14 Dec 2022
Edited: Image Analyst
on 14 Dec 2022
You need to subtract the images (assuming they're well aligned) with imabsdiff. If they're not well aligned, you may have to use imregister depending on how bad the misalignment is. This will give you a difference image. If it's color you might then have to call max() or rgb2gray. Then threshold like
mask = diffImage > 10; % Or whatever works well.
Then call bwlabel. If it returns a count more than 0 (it's not "empty") then there is a large enough blob that is missing from your test image (it was in ref image but not in test image), or the test image has an extra object in there that someone added.
If you need a full step-by-step image segmentation demo where I walk you through it, see my Image Processing Tutorial in my File Exchange:
0 Comments
See Also
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!