How to segment black pixels from a colour image?

3 次查看(过去 30 天)
I have a colour image. From this image I have to remove the black circles and black symbols from it. How can I do it?

回答(2 个)

Stalin Samuel
Stalin Samuel 2016-2-15

DGM
DGM 2023-4-30
编辑:DGM 2023-4-30
If you want to clean up that image, start by deleting it and getting the original image before it was reduced to a microscopic JPG pixel salad.
% read the garbage image
inpict = imread('if_you_want_to_ruin_your_image_save_it_as.jpeg');
% 75% of chroma information has been discarded
% so H, S are mostly useless for any task selecting small features
% just use luma alone to select the region
mask = rgb2gray(inpict)<110;
% get rid of single-pixel speckles
mask = bwareaopen(mask,2);
% show the mask
imshow(mask,'border','tight')
% inpaint the masked region
outpict = inpict;
for c = 1:size(inpict,3)
outpict(:,:,c) = regionfill(inpict(:,:,c),mask);
end
% show the image
imshow(outpict,'border','tight')
But wait! Now there's a 10px-wide halo of garbage all around where the black lines were! Surprise! Those were there to begin with.
So what are the lessons?
  • If you can create a mask to define a region of an image that you want to inpaint based on its immediate surroundings, you can use regionfill().
  • Don't save images as JPG unless you understand the amount of information you're throwing away. Generally, don't use JPG for any technical purposes where images need to be reprocessed.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by