How to make image background white?

조회 수: 7 (최근 30일)
Zara Khan
Zara Khan 2019년 12월 24일
댓글: Zara Khan 2019년 12월 28일
I have a binary image. I want to make the background white keeping the black straight lines intact.I mean those lines which intersecting image objects will remain intact. Picture has attached.

채택된 답변

Jeff E
Jeff E 2019년 12월 24일
I would start by closing in small gaps to get a solid hand.
imgin_close = imclose(imgin, strel('square', 3));
Then I would find the overlap between that solid hand, and the inverse of the original image, leaving me with just white lines on a black background. You may have some additional noise around the edges of the hand. The could be filtered out with something like bwareaopen, depending on your application.
imgin_lines = imgin_close & ~imgin;
imgin_lines = bwareaopen(imgin_lines, 3);
I would then take the inverse of that image to get just the black lines.
imgout = ~imgin_lines;
  댓글 수: 5
Image Analyst
Image Analyst 2019년 12월 26일
Zara, I'm not sure what your question means. What do you want to give black lines "to"? What other colours are there that should receive/get black lines?
Or do you mean "how can I display the black lines in a variety of colors?" If that is what you mean, then label the lines-only image and call label2rgb().
% Label each line with a unique ID number.
labeledImage = bwlabel(imgin_lines)
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
imshow(coloredLabels);
Zara Khan
Zara Khan 2019년 12월 28일
Image Analyst: Wonderful. Exactly this is what I was asking for.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by