I am was trying to crop minAreaRect and I got the following result, with black padding to cover up missing parts. I want to replace that black padding with white pixels.
Asked
Active
Viewed 224 times
1 Answers
0
I am replacing the black pixels with white pixels using cv2. I am reading the image in black and white.
img = cv2.imread('input_image',0)
As the img now is a numpy array, The fastest and most concise way to replace black pixels to white is to use Numpy's builtin indexing. Here I am replacing all 0 values in the image to 255(white). The time taken for this operation is 0.00011920928955078125 seconds.
img[img == 0] = 255

Amog Chandrashekar
- 277
- 2
- 8
-
That's great, but there's still a black line between the image and the padded white pixels. How can we get rid of them? – Dhiraj Kadam Oct 01 '18 at 10:28
-
@DhirajKadam Those lines are because the pixels in those spots are more than 0 and less than 100, if you want to remove all those black points, change condition to img[img<100]=255, but this adds some amount of distortion to the image(removes some black spots from the image). Please up vote the answer, if you found it to be useful. – Amog Chandrashekar Oct 01 '18 at 10:56
-
Thank you. I'm new so StackOverflow doesn't allow me to upvote yet. However, I accepted it as the answer. – Dhiraj Kadam Oct 01 '18 at 11:03