如何在matlab中遮盖图像的一部分?
我想知道如何遮盖黑色和白色图像的一部分白色的 ?
我有一个需要进行边缘检测的物体,但背景中有其他白色干扰物体位于目标物体下方...我想将图像的整个下部遮盖为黑色,我该怎么做?
谢谢 !!
编辑
我还想掩盖一些其他部分(顶部部分)......我该怎么做?
请解释一下代码,因为我真的想了解它是如何工作的并以我自己的理解来实现它。
EDIT2
我的图像是 480x640 ...有没有办法掩盖特定像素?例如图像中的 180x440 ...
I would like to know how to mask part of an image that is in BLACK & WHITE ?
I got an object that needs to be edge detected, but I have other white interfering objects in the background that are below the target objet ... I would like to mask the entire lower part of an image to black, how can I do that ?
Thanks !!
EDIT
I also want to mask some other parts (top part) ... how can I do that ?
Please explain the code because I really wnat to learn how it works and implement it in my own understanding.
EDIT2
My image is 480x640 ... Is there a way to mask specific pixels ? for example 180x440 from the image ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有二维灰度强度图像存储在矩阵
A
中,您可以通过执行以下操作将下半部分设置为黑色:首先使用函数 SIZE,将其除以 2,然后四舍五入off 以获得图像高度中心附近的整数索引。然后,向量
centerIndex:end
索引从中心索引到末尾的所有行,并且:
索引所有列。所有这些索引元素都设置为 0 以表示黑色。函数 CLASS 用于获取数据类型
A
以便可以使用函数 演员。不过,这可能不是必需的,因为没有它们,0可能会自动转换为A
类型。如果您想创建逻辑索引< /a> 要用作掩码,您可以执行以下操作:
现在,
mask
是一个逻辑矩阵,其中true
(即“1”)代表您想要保留的像素和false
(即“0”)表示要设置为 0 的像素。您可以根据需要将mask
的更多元素设置为false
。然后,当您想要敷面膜时,可以执行以下操作:If you have a 2-D grayscale intensity image stored in matrix
A
, you can set the lower half to black by doing the following:This works by first getting the number of rows in
A
using the function SIZE, dividing that by 2, and rounding it off to get an integer index near the center of the image height. Then, the vectorcenterIndex:end
indexes all the rows from the center index to the end, and:
indexes all the columns. All of these indexed elements are set to 0 to represent the color black.The function CLASS is used to get the data type of
A
so that 0 can be cast to that type using the function CAST. This may not be necessary, though, as 0 will probably be automatically converted to the type ofA
without them.If you want to create a logical index to use as a mask, you can do the following:
Now,
mask
is a logical matrix withtrue
(i.e. "1") for pixels you want to keep andfalse
(i.e. "0") for pixels you want to set to 0. You can set more elements ofmask
tofalse
as you wish. Then, when you want to apply the mask, you can do the following: