1

我有一个原始灰度图像(我正在使用带有图像外部标签的乳房 X 线照片图像)。我需要删除该图像中的一些对象(标签),因此我将该灰度图像转换为二进制图像。然后我按照 如何选择面积最大的对象中提供的答案方法

最后我提取了一个面积最大的对象作为二值图像。我想要那个灰度区域来访问和分割其中的小对象。例如。区域内的小组织,也应检测其边缘。

提取的二进制图像原始灰度图像

**

我怎样才能将分离的对象区域作为灰度图像或无论如何直接从灰度获得最大的对象区域而不转换为二进制或任何其他方式。?

**

(我是matlab的新手。我不知道我是否解释正确。如果你不能得到,我会提供更多细节)

4

2 回答 2

1

如果我理解正确,您正在寻找只有最大斑点被突出显示的灰色图像。

代码

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)

输出

在此处输入图像描述

于 2014-04-09T07:15:21.427 回答
1

如果我正确理解您的问题,您想使用二进制地图并访问这些区域中相应的像素强度。

如果是这样的话,那就很简单了。您可以使用二进制地图来识别您想要访问原始图像中强度的位置的空间坐标。创建一个空白图像,然后使用这些空间坐标将这些强度复制到空白图像。

这是一些您可以使用的示例代码。

% 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');

让我知道这是否是您正在寻找的。

方法#2

正如 Rafael 在他的评论中所建议的,您可以跳过 using findall together 并使用逻辑语句:

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

我决定使用find它,因为它对初学者来说不太容易混淆,尽管这样做效率较低。任何一种方法都会给你正确的结果。


一些思考的食物

您在二进制图像中提取的区域有几个孔。我怀疑您会想抓住整个区域而没有任何漏洞。因此,我建议您在使用上述代码之前填补这些漏洞。imfillMATLAB中的函数运行良好,它接受二进制图像作为输入。

在此处查看文档:http: //www.mathworks.com/help/images/ref/imfill.html

因此,imfill首先应用到您的二进制图像,然后继续使用上面的代码进行提取。

于 2014-04-09T00:00:05.830 回答