Skip to content Skip to sidebar Skip to footer

How To Stop Numpy Hstack From Changing Pixel Values In Opencv

I'm trying to get an image to display in python using opencv, with a side pane on it. When I use np.hstack the main picture becomes unrecognizably white with only a small amount of

Solution 1:

The only way I can see that happening is if the data types between the two images don't agree. Make sure that inside your return_annotated method, both img_with_gt and gt_pane both share the same data type.

You mentioned the fact that you're allocating space for the gt_pane to be float64. This represents intensities / colours within the span of [0-1]. Convert the image to uint8 and multiply the result by 255 to ensure compatibility between the two images. If you want to leave the image untouched and work on the classification image (the right one), convert to float64 then divide by 255.

However, if you want to leave the method untouched, a simple fix could can be:

both = np.hstack(((255*img_with_gt).astype(np.uint8), gt_pane))

You can also go the other way around:

both = np.hstack((img_with_gt, gt_pane.astype(np.float64)/255.0))

Post a Comment for "How To Stop Numpy Hstack From Changing Pixel Values In Opencv"