2

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 color. Here's my code:

    img = cv2.imread(filename)
    img_with_gt, gt_pane = Evaluator.return_annotated(img, annotations)
    both = np.hstack((img_with_gt, gt_pane))

    cv2.imshow("moo", both)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

And here is the resulting picture

corrupted hstack image

But If I view img_with_gt it looks correct.

groundtruth correct

Even works with gt_pane

gt pane correct

I can't seem to figure out why this is happening.

3
  • What are the data types of both images? Specifically, what happens when you do img_with_gt.dtype and gt_pane.dtype in the REPL? Are they both the same class? Commented Jul 7, 2015 at 17:59
  • gt_pane is float64, img_with_gt is uint8..I changed the construction with the optional dtype in my call to np.zeroes and it worked perfectly. Thanks!! If you answer it I can give you the check mark. Commented Jul 7, 2015 at 18:10
  • There we go. It was a conflict in data type. Yup, let me write an answer now :) Commented Jul 7, 2015 at 18:11

1 Answer 1

3

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.