I have to get a image, apply Histogram equalization and plot the histogram of both images (original and modified). So I tried this code:
JavaScript
x
19
19
1
import cv2
2
import numpy as np
3
from skimage import io, img_as_float, img_as_ubyte
4
import matplotlib.pyplot as plt
5
from matplotlib import pyplot as plt
6
7
gray = cv2.imread("folderimg1.jpg",0)
8
9
10
equ = cv2.equalizeHist(gray)
11
12
io.imshow(gray)
13
io.imshow(equ)
14
15
histr = cv2.calcHist([gray],[0],None,[256],[0,256])
16
17
plt.plot(histr)
18
plt.show()
19
How can I fix it?
Advertisement
Answer
You are not creating a new figure, so the histogram is plotted on the last figure that displays the image.
You may create a new figure before plotting the histogram:
JavaScript
1
6
1
histr = cv2.calcHist(gray, [0], None, [256], (0,255))
2
3
plt.figure() # Create new figure for the histogram plot
4
plt.plot(histr)
5
plt.show()
6