LoslegenKostenlos loslegen

Histograms

Histograms display the distribution of values in your image by binning each element by its intensity then measuring the size of each bin.

The area under a histogram is called the cumulative distribution function. It measures the frequency with which a given range of pixel intensities occurs.

For this exercise, describe the intensity distribution in im by calculating the histogram and cumulative distribution function and displaying them together.

Diese Übung ist Teil des Kurses

Biomedical Image Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Import scipy.ndimage as ndi.
  • Generate a 256-bin histogram of im which covers the full range of np.uint8 values.
  • Calculate the cumulative distribution function for im. First, find the cumulative sum of hist, then divide by the total number of pixels in hist.
  • Plot hist and cdf on separate subplots. This has been done for you.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Import SciPy's "ndimage" module
import ____ as ____ 

# Create a histogram, binned at each possible value
hist = ____

# Create a cumulative distribution function
cdf = hist.cumsum() / ____

# Plot the histogram and CDF
fig, axes = plt.subplots(2, 1, sharex=True)
axes[0].plot(hist, label='Histogram')
axes[1].plot(cdf, label='CDF')
format_and_render_plot()
Code bearbeiten und ausführen