1

I have this image: enter image description here

In this image I have 11 shapes (look like ellipses). I want to find the RGB of each pixel in each shape (including the white edge/boundary, as it's a part of the shape).

If it helps, I have the center coordinate of each shape.

Thanks a lot!

Superbest
  • 25,318
  • 14
  • 62
  • 134
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138

2 Answers2

2

This is a hacky solution that occurred to me as I was reviewing the question:

  1. Fill each shape with white as was described in your other question, Matlab fill shapes by white.
  2. Since you still have the centers of shapes, now fill each shape again with a color not present in your image, like pink.
  3. Now every pixel of interest (those which belong to the shape: edge and inside) is colored pink, and no other pixel has this color.
  4. Now you can simply get a list of pink pixels:

    foundPixels = find(img == pink); % pink holds the value for the pink color I used.

  5. Now you can use these indices on the original image (pixels = original(foundPixels);) to obtain the pixels you want.

Community
  • 1
  • 1
Superbest
  • 25,318
  • 14
  • 62
  • 134
2

here are the commands that makes your work easy...

  1. As "Superbest" said fill the image with command

    %% Example%%
    img = imread('coins.png');
    BW4 = im2bw(img );
    BW5 = imfill(BW4,'holes');
    imshow(BW4), figure, imshow(BW5);
    
  2. Now use command bwlabeln(), to find out the number of clusters or shapes.

    %% Example%%
     L = bwlabel(BW5);
     figure,imshow(L,[]);
    

L will give you number of shapes with same number to all the pixels belongs to same shape. L containing labels for the connected components in BW. BW can have any dimension; L is the same size as BW. The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object, the pixels labeled 2 make up a second object, and so on.

  1. Suppose you have two shapes or regions then to find the original color or gray scale values od as follows.

    %% Example%%
    cods = find(L==1);
    Shape1(1:size(img,1),1:size(img,2))=0;
    Shape1(cods) = img(cods);
    %% Now shape1 is same size as img, but will have gray scale values at region1   locations only,you will get RGB valuse in shape1 image.. repeate it for as many shapes as you have in your image.
    

Have a happy coding...

G453
  • 1,446
  • 10
  • 13