0

I have to get a image, apply Histogram equalization and plot the histogram of both images (original and modified). So I tried this code:

import cv2
import numpy as np
from skimage import io, img_as_float, img_as_ubyte
import matplotlib.pyplot as plt  
from matplotlib import pyplot as plt

gray = cv2.imread("folder\img1.jpg",0)


equ = cv2.equalizeHist(gray)

io.imshow(gray)
io.imshow(equ)

histr = cv2.calcHist([gray],[0],None,[256],[0,256])
  
plt.plot(histr)
plt.show()

But The plot returned is..: enter image description here

How can I fix it?

1

1 Answer 1

1

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:

histr = cv2.calcHist(gray, [0], None, [256], (0,255))

plt.figure() # Create new figure for the histogram plot
plt.plot(histr)
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.