如果我正确理解您的问题,您想使用二进制地图并访问这些区域中相应的像素强度。
如果是这样的话,那就很简单了。您可以使用二进制地图来识别您想要访问原始图像中强度的位置的空间坐标。创建一个空白图像,然后使用这些空间坐标将这些强度复制到空白图像。
这是一些您可以使用的示例代码。
% 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 find
all together 并使用逻辑语句:
outImg = img;
outImg(~bmap) = 0;
我决定使用find
它,因为它对初学者来说不太容易混淆,尽管这样做效率较低。任何一种方法都会给你正确的结果。
一些思考的食物
您在二进制图像中提取的区域有几个孔。我怀疑您会想抓住整个区域而没有任何漏洞。因此,我建议您在使用上述代码之前填补这些漏洞。imfill
MATLAB中的函数运行良好,它接受二进制图像作为输入。
在此处查看文档:http: //www.mathworks.com/help/images/ref/imfill.html
因此,imfill
首先应用到您的二进制图像,然后继续使用上面的代码进行提取。