I have a grayscale image and a binary image, and I want to plot them side by side using hstack. It looks like there is kind of adjustment that been made yielding to darken the binary. Anybody faced this problem?
Here is my code
O = (self.img >= t) * 1
I = img
both = np.hstack((I, O))
imshow(both, cmap='gray')
show()
This is to demonstrate a somewhat different from your case which I don't know of its data. I suspect that all the values in your array 'O' are zero, thus, the plot came out as a black pane.
import numpy as np
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(8, 4))
# make up some data for demo purposes
raw = np.random.randint(10, size=(6,6))
# apply some logic operatioin to the data
O = (raw >= 5) * 1 # get either 0 or 1 in the array
I = np.random.randint(10, size=(6,6)) # get 0-9 in the array
# plot each image ...
# ... side by side
fig.add_subplot(1, 2, 1) # subplot one
plt.imshow(I, cmap=plt.cm.gray)
fig.add_subplot(1, 2, 2) # subplot two
# my data is OK to use gray colormap (0:black, 1:white)
plt.imshow(O, cmap=plt.cm.gray) # use appropriate colormap here
plt.show()
The resulting image:

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