如何在Matlab中基于二进制蒙版标记的ROI上应用图像处理算法? [英] How to apply image processing algorithms on the ROI labeled based on a binary mask in Matlab?

查看:279
本文介绍了如何在Matlab中基于二进制蒙版标记的ROI上应用图像处理算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制遮罩,标记了图像的前景.直方图均衡或otsu方法等许多图像处理算法都可以处理整个图像.我的问题是如何应用这些图像处理算法,以便它们只能处理我的二进制蒙版标记的区域?

I have a binary mask which labeled the foreground of image. Many image processing algorithms such as histogram equalization or otsu method deal with the whole image. My question is how to apply those image processing algorithms so that they can ONLY process the region which my binary mask labeled?

例如,I是灰度图像,BW是二进制掩码.下面的代码仍然处理整个图像,而不是BW蒙版标记的特定区域.

For example, I is the grayscale image and BW is the binary mask. The code below still process the whole image rather than the specific region labeled by the BW mask.

level = graythresh(I.*BW);
BW = im2bw(I.*BW,level);

推荐答案

代码的问题在于,您只是将图像的元素设置为零.相反,您应该只将感兴趣的体素传递给grayscale算法.例如,如果ROI中的BW不为零,则可以说

The problem with your code is that you are just setting elements of the image to zero. Instead, you should only pass the voxels of interest to the grayscale algorithm. For example, if BW is nonzero in the ROI, you can say

level = graythresh(I(BW>0));

这将仅选择要用于阈值计算的元素.这是

That will select only the elements you want for the threshold calculation. It is shorthand for

level = graythresh(I(find(BW>0)));

表达式的第二种形式创建带有索引的中间数组-通常比使用逻辑索引(这种索引称为逻辑索引)要慢.

This second form of the expression creates an intermediate array with the indices - which is usually slower than using logical indexing (which is what this kind of index is called).

这篇关于如何在Matlab中基于二进制蒙版标记的ROI上应用图像处理算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆