Problem on 'bitand' method

조회 수: 2 (최근 30일)
nayomi ranamuka
nayomi ranamuka 2011년 4월 7일
Hi friends,
I have problem on 'bitand' method when create marker image using mask.
I2 = im2bw(I1,0.8); %%Thresholding image(Create a mask)
I2Cmp = ~ I2; %%Invert the mask
marker=bitand(1,I2Cmp); %%Create marker image
There is an error when creating marker.
??? Error using ==> bitand Inputs must be non-negative integers.
How would I apply bitand for creating a maker ????
  댓글 수: 2
David Young
David Young 2011년 4월 7일
Could you explain what the marker image should be? It's not clear why you would want to use bitand at all in this context, and I wonder if you need something completely different. I2 and I2Cmp are logical arrays, so there is only one bit of information per pixel anyway.
nayomi ranamuka
nayomi ranamuka 2011년 4월 7일
Marker image is the result when apply bitand method for I1 and I2Cmp images. I want to ovelay the inverted image of I2 on I1 .
How would I apply bitand method ?

댓글을 달려면 로그인하십시오.

채택된 답변

Laura Proctor
Laura Proctor 2011년 4월 7일
I don't think that you actually need to use BITAND. I think what you would like to do is create marker that consists of all ones and zeros. To do this, just use the following code to create a logical array:
marker = I2Cmp > 0;
Then, to overlay this on I1, simply use element-wise multiplication:
Iresult = I1.*marker;
  댓글 수: 1
Steve Eddins
Steve Eddins 2011년 4월 7일
I2Cmp is already logical, so the first line of code in this answer is not necessary.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Steve Eddins
Steve Eddins 2011년 4월 7일
The general answer is to use the elementwise logical operators &, |, and ~ instead of bitand and bitor to do this sort of manipulation with binary images.
To "overlay the inverted image of I2 on I1," as you say, you would do this:
marker = I1 | ~I2;
  댓글 수: 2
David Young
David Young 2011년 4월 7일
Steve, I don't think I1 is logical.
Steve Eddins
Steve Eddins 2011년 4월 7일
David, you're right, sorry.

댓글을 달려면 로그인하십시오.


nayomi ranamuka
nayomi ranamuka 2011년 4월 7일
This is my solution. marker=bitand(im2uint8(I1),im2uint8(I2Cmp));
Thanx for your answers.

Steve Eddins
Steve Eddins 2011년 4월 7일
Here's a different kind of overlay:
Iresult = I1;
Iresult(ICmp) = 255; % assuming I1 is uint8
This version turns all the marker pixels white and leaves the others alone.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by