In the answer to this question, I wanted to display the image in its original colors, and so removed the gray
parameter from this line of code:
plt.imshow(im_out, 'gray')
When doing this however I get the image displayed with yellow and purple colors as opposed to the image's original colors.
What should I do to display the image with its original colors?
Thanks.
EDIT 1 I came across this tutorial, and seems that I should use:
plt.imshow(cv2.cvtColor(im_out, cv2.COLOR_BGR2RGB))
However, when I did this, I got the following:
Calculated scale difference: 0.99
Calculated rotation difference: 44.51
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/user/opencv/modules/imgproc/src/color.cpp, line 10606
Traceback (most recent call last):
File "align_surf.py", line 47, in <module>
deskew()
File "align_surf.py", line 9, in deskew
plt.imshow(cv2.cvtColor(im_out, cv2.COLOR_BGR2RGB))
cv2.error: /home/user/opencv/modules/imgproc/src/color.cpp:10606: error: (-215) scn == 3 || scn == 4 in function cvtColor
How can I fix this issue?
EDIT 2 The reason of the above was that the image was read as follows in the original code:
orig_image = cv2.imread('1.jpg', 0)
So, I simply removed 0
.
If you want to save a color image (3D ndarray ) as a grayscale image file, convert it to grayscale with cv2. cvtColor() and cv2. COLOR_BGR2GRAY . If you save 2D ndarray to a file and read it again with cv2.
Based on this tutorial, in order to fix the issue, I had to convert BGR
to RGB
, as follows:
plt.imshow(cv2.cvtColor(im_out, cv2.COLOR_BGR2RGB))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With