Ask Your Question
1

imshow can not correctly show a png file

asked Mar 22 '18

outwalllife gravatar image

updated Oct 24 '0

when I try to imshow a png image description

it show noting.

But I can use the chrome open the png file and show it.

Preview: (hide)

Comments

It shows nothing ? What does it mean? opencv is an image processing library It does not process alpha channel

LBerger gravatar imageLBerger (Mar 22 '18)edit

please show your code. most likely, there's something simple missing, like a waitkey().

berak gravatar imageberak (Mar 22 '18)edit
2

Well, your image is transparent. So when you display it, every pixel is either background (black) or black. That's why you don't see anything.

kbarni gravatar imagekbarni (Mar 22 '18)edit

So how should I display it. I export a pcb file to pdf, and then I open pdf by office word2016, and then I save this picture to png file, and I can not imshow it .

outwalllife gravatar imageoutwalllife (Mar 23 '18)edit

you use word for image manipulation ? lol. that sounds bad.

berak gravatar imageberak (Mar 23 '18)edit

1 answer

Sort by » oldest newest most voted
2

answered Mar 23 '18

berak gravatar image

updated Mar 23 '18

unfortunately, given the weird and complicated pipeline you used, when creating this image, ALL information is in the alpha channel (ONLY!).

so, needs a small detour to make it visible:

im = cv2.imread("platine.png", -1) # keep alpha
alpha = im[:,:,3] # extract it
binary = ~alpha   # invert b/w
cv2.imshow("P",binary)
cv2.waitKey()

imho you should avoid anything with alpha in it, it only causes trouble.

you probably should try to change your pipeline, so it saves a single channel image, with black contours on white bg, instead of trying to mend it later like above.

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 22 '18

Seen: 8,540 times

Last updated: Mar 23 '18