1

I have a original gray scale image(I m using mammogram image with labels outside image). I need to remove some objects(Labels) in that image, So i converted that grayscale image to a binary image. Then i followed the answer method provided in How to Select Object with Largest area

Finally i extracted an Object with largest area as binary image. I want that region in gray scale for accessing and segmenting small objects within that. For example. Minor tissues in region and also should detect its edge.

Extracted Binary imageOriginal Gray Scale Image

**

How can i get that separated object region as grayscale image or anyway to get the largest object region from gray scale directly without converting to binary or any other way.?

**

(I am new to matlab. I dono whether i explained it correctly or not. If u cant get, I ll provide more detail)

Community
  • 1
  • 1
Cholavendhan
  • 337
  • 1
  • 5
  • 11

2 Answers2

1

If I understand your question correctly, you want to use the binary map and access the corresponding pixel intensities in those regions.

If that's the case, then it's very simple. You can use the binary map to identify the spatial co-ordinates of where you want to access the intensities in the original image. Create a blank image, then copy over these intensities over to the blank image using those spatial co-ordinates.

Here's some sample code that you can play around with.

% Assumptions:
% im - Original image
% bmap - Binary image 

% Where the output image will be stored
outImg = uint8(zeros(size(im)));

% Find locations in the binary image that are white
locWhite = find(bmap == 1);

% Copy over the intensity values from these locations from
% the original image to the output image.
% The output image will only contain those pixels that were white
% in the binary image
outImg(locWhite) = im(locWhite);

% Show the original and the result side by side
figure;
subplot(1,2,1);
imshow(im); title('Original Image');
subplot(1,2,2);
imshow(outImg); title('Extracted Result');

Let me know if this is what you're looking for.

Method #2

As suggested by Rafael in his comments, you can skip using find all together and use logical statements:

outImg = img; 
outImg(~bmap) = 0;

I decided to use find as it less obfuscated for a beginner, even though it is less efficient to do so. Either method will give you the correct result.


Some food for thought

The extracted region that you have in your binary image has several holes. I suspect you would want to grab the entire region without any holes. As such, I would recommend that you fill in these holes before you use the above code. The imfill function from MATLAB works nicely and it accepts binary images as input.

Check out the documentation here: http://www.mathworks.com/help/images/ref/imfill.html

As such, apply imfill on your binary image first, then go ahead and use the above code to do your extraction.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • 1
    You can do it directly without using `find`: `outImg = img; outImg(~bmap) = 0;` – Rafael Monteiro Apr 09 '14 at 00:48
  • 1
    I chose to use `find` as the OP stated that he/she was a beginner. It's less obfuscated (though less efficient I will admit) through the use of `find`.... in my opinion anyway. – rayryeng Apr 09 '14 at 00:56
  • Thank you.. Just 2 lines. But Does the job perfectly. Easy to understood.. Tnk u.. – Cholavendhan Apr 11 '14 at 13:36
  • But it cannot preserve edges sharply or even closer. Depends on threshold value i use for binary image conversion. (Initially i used greythresh() function then i manually used 0.2 as mentioned in above answer. – Cholavendhan Apr 11 '14 at 13:54
  • I have extracted the pixels above certain intensity. But right top body part also comes into the extracted part. I want only the breast region. Is there any way to crop or segment the particular breast region without body regions in image.? – Cholavendhan Apr 13 '14 at 07:53
  • If the intensities of the right top body part are consistently like that, then what you could do is generate another binary mask with a threshold that is higher than the majority of the intensities of the breast matter and high enough to capture those intensities for the right top body part. After that, remove these portions from the first binary image you generated containing both the breast and the body part using this second image. This will obviously remove some parts of the breast, so you can use `imfill` to refill those gaps. – rayryeng Apr 14 '14 at 05:04
1

If I understood you correctly, you are looking to have a gray image with only the biggest blob being highlighted.

Code

img = imread(IMAGE_FILEPATH);
BW = im2bw(img,0.2); %%// 0.2 worked to get a good area for the biggest blob

%%// Biggest blob
[L, num] = bwlabel(BW);
counts = sum(bsxfun(@eq,L(:),1:num));
[~,ind] = max(counts);
BW = (L==ind);

%%// Close the biggest blob
[L,num] = bwlabel( ~BW );
counts = sum(bsxfun(@eq,L(:),1:num));
[~,ind] = max(counts);
BW = ~(L==ind);

%%// Original image with only the biggest blob highlighted
img1 = uint8(255.*bsxfun(@times,im2double(img),BW));

%%// Display input and output images
figure,
subplot(121),imshow(img)
subplot(122),imshow(img1)

Output

enter image description here

Divakar
  • 218,885
  • 19
  • 262
  • 358