How to extract only object with white background using bounding box in MatLab?

3 visualizaciones (últimos 30 días)

Hi everyone,

I am a newbie in matlab.

I try to do segmentation to get seperately image and text in an image.

I use regionprops, so i got each boundingbox and one of the image is like this:

My problem is that I crop the original image to get each connected component using boundingbox. However, I want only the object for instance the coin with white background.

Any idea ?

_ EDITED _

I crop the original image to get each connected component using boundingbox .

My problem is that when the original image are cropped in rectangle shape, some background of the crop image have coin(that what i want) and some text or line within the rectangle shape (that i dont want),

How can I remove those text or line within the rectangle shape of the crop image?

  2 comentarios
Bruno Pop-Stefanov
Bruno Pop-Stefanov el 20 de En. de 2014
Just to clarify what you would like to do: you would like to get bounding boxes on objects extracted from an image, but you only want the object itself and not what is in the background? For example, in the image you provided, you would like to extract bounding boxes around each of the four coins?
Vortana
Vortana el 21 de En. de 2014
Sorry for confusing,
I already found the connected components and i can crop the image using their bounding box.
I crop the original image to get each connected component using boundingbox .
My problem is that when the original image are cropped in rectangle shape, some background of the crop image have coin(that what i want) and some text or line within the rectangle shape (that i dont want),
How can I remove those text or line within the rectangle shape of the crop image?

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Pop-Stefanov
Bruno Pop-Stefanov el 20 de En. de 2014
Editada: Bruno Pop-Stefanov el 21 de En. de 2014
I think what you are looking for is activecontour. Active contours allow you to separate an image into foreground and background.
Using the image of coins you provided, the following code generates a binary image bw in which white pixels belong to the foreground (coins) and black pixels belong to the background:
% Open image
I = imread('coins.jpg');
% Convert to grayscale
I = rgb2gray(I);
% Show image
figure(1);
imshow(I)
title('Image with objects')
% mask is the initial contour state
mask = zeros(size(I));
mask(25:end-25,25:end-25) = 1;
% Show mask
figure(2);
imshow(mask);
title('Initial contour location')
% bw is a mask of the detected objects
numIter = 2500;
bw = activecontour(I, mask, numIter);
% Show detected objects
figure(3);
imshow(bw);
title('Detected objects')
When using activecontour, keep in mind that the default number of iterations is 100. Depending on the image you are working on, you might want to change that to a larger number of iterations. In the example code above I chose 2500 and all four coins are successfully separated.
Then, you can use the bwconncomp function to find each coin in the image as a connected component. However, noise might be present in bw after running active contours. You can use the bwareaopen function to perform a morphological opening on the binary image bw and remove connected components that have less than a certain number of pixels.
I included the entire script (extractCoins.m) with all operations, from opening the image to cropping the coins from their background and displaying them. This is the final result:
  17 comentarios
Bharath Kumar
Bharath Kumar el 19 de Jun. de 2020
how to higlighted as per specific value of coin

Iniciar sesión para comentar.

Más respuestas (1)

Nivetha m
Nivetha m el 15 de Abr. de 2016
I want to be extract text from given image...... please help me to solve this problem...

Categorías

Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by