简体   繁体   English

MATLAB逻辑图像uint8图像乘法

[英]MATLAB logical image uint8 image multiplication

I have two images. 我有两个图像。 1st one is with data type uint8. 第一个是数据类型为uint8。 2nd one with data type logical. 第二个具有逻辑数据类型。 I want to multiply these two images so that I can replace the "1" values of 2nd image by the intensity values of 1st image. 我想将这两个图像相乘,以便可以用第一图像的强度值替换第二图像的“ 1”值。 How can I do that? 我怎样才能做到这一点?

I'm going to call the image img and the logical matrix mask and assume same size. 我将调用图像img和逻辑矩阵mask并假设大小相同。 Using logical indexing you can do 使用逻辑索引,您可以执行

img(~mask) = 0;

which should be faster than multiplication. 这应该比乘法快。

I assume both images have the same size. 我假设两个图像的大小相同。

Then you can just do a element-wise multiplication .* , but you obviously first have to conver to the same type, so that would result in following code: 然后,您可以进行逐元素乘法.* ,但是显然您首先必须转换为相同的类型,这样将导致以下代码:

uint8_image .* uint8(logical_image)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM