Revision history [back]

Understanding bitwise_and operation

Hi all, I'm new to openCV. I'm a bit confused about bitwise operation. Appreciate if you can help me to clarify some things.

1. Bitwise operation is for binary image only? cause from the (admittedly limited) code that I've seen, it doesn't seem so. I don't get how AND OR ,etc operation to be applied to non binary ? please explain on this
2. I read this documentation on bitwise_and.

What I understand is that : the result is equal to src1 & src2 , if the mask for that element is not zero. My question is that if mask for that element is zero, what is result equal to? is it equal to the element in src1 or src2?

----.

Lastly, please help me to understand the following code from ROS

image = self.bridge.imgmsg_to_cv2(msg) [0]
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) [1]
lower_yellow = numpy.array([ 50,  50, 170]) [2]
upper_yellow = numpy.array([255, 255, 190]) [3]
mask = cv2.inRange(hsv, lower_yellow, upper_yellow) [4]


[0] This line is just to convertimage from ROS image format to openCV image format. Shortly image is a RGB image.

[1] convert image form RGB to HSV

[2] set the lower limit for yellow color

[3] set the upper limit for yellow color

[4] producing a binary image : the element that is in the range of lower_yellow and upper_yellow gives 1, and the rest give 0. So mask is a binary image, with the section that qualify as yelloq =1 , and 0 for the rest.

[5] I don't really understand this part. We are operate bitwise_and on image & itself? image is RGB ,not binary, how to operate AND on RGB? Please explain

Thanks

Understanding bitwise_and operation

Hi all, I'm new to openCV. I'm a bit confused about bitwise operation. Appreciate if you can help me to clarify some things.

1. Bitwise operation is for binary image only? cause from the (admittedly limited) code that I've seen, it doesn't seem so. I don't get how AND OR ,etc operation to be applied to non binary ? please explain on this
2. I read this documentation on bitwise_and.

What I understand is that : the result is equal to src1 & src2 , if the mask for that element is not zero. My question is that if mask for that element is zero, what is result equal to? is it equal to the element in src1 or src2?

----.

Lastly, please help me to understand the following code from ROS

image = self.bridge.imgmsg_to_cv2(msg) [0]
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) [1]
lower_yellow = numpy.array([ 50,  50, 170]) [2]
upper_yellow = numpy.array([255, 255, 190]) [3]
mask = cv2.inRange(hsv, lower_yellow, upper_yellow) [4]


[0] This line is just to convertimage from ROS image format to openCV image format. Shortly image is a RGB image.

[1] convert image form RGB to HSV

[2] set the lower limit for yellow color

[3] set the upper limit for yellow color

[4] producing a binary image : the element that is in the range of lower_yellow and upper_yellow gives 1, and the rest give 0. So mask is a binary image, with the section that qualify as yelloq =1 , and 0 for the rest.

[5] I don't really understand this part. We are operate do bitwise_and operation on image & with itself? What for? Also, image is RGB ,not binary, how to operate AND on RGB? Please explain

Thanks