How to make image background white?

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.

 Respuesta aceptada

Jeff E
Jeff E el 24 de Dic. de 2019
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 comentarios

using imshow(imgout) showing me this error.
Error in imshow (line 227)
[common_args,specific_args] = ...
Error in prog1 (line 10)
imshow(imgin_lines);
This is what his code gives for me:
imgin = imread('image.png');
subplot(2, 3, 1);
imshow(imgin);
% Make a binary image
if ~isa(imgin, 'logical')
imgin = imgin(:, :, 1) > 128;
end
imgin_close = imclose(imgin, strel('square', 3));
subplot(2, 3, 2);
imshow(imgin_close);
imgin_lines = imgin_close & ~imgin;
subplot(2, 3, 3);
imshow(imgin_lines);
imgin_lines = bwareaopen(imgin_lines, 3);
subplot(2, 3, 4);
imshow(imgin_lines);
% I would then take the inverse of that image to get just the black lines.
imgout = ~imgin_lines;
subplot(2, 3, 5);
imshow(imgout);
0000 Screenshot.png
Zara Khan
Zara Khan el 26 de Dic. de 2019
Image Analyst: Thank you. It has solved my problem. Can I give black lines to any other colours ??
Jeff E: thank you. I have accepted your answer.
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 el 28 de Dic. de 2019
Image Analyst: Wonderful. Exactly this is what I was asking for.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 24 de Dic. de 2019

Comentada:

el 28 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by