Calculate two dimensional histogram of a given image.
Project description
im2dhist
This small piece of code is intended to help researchers, especially in the field of image processing, to easily calculate two dimensional histogram of a given image.
Installation
Run the following to install:
pip install im2dhist
Usage
from im2dhist import im2dhist
import cv2
import numpy as np
from mpl_toolkits import mplot3d
import matplotlib.pyplot as plt
def main():
image_name = 'Plane.jpg'
image = cv2.imread(image_name)
# converts rgb image to gray
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 2*w_neighboring+1 is width of the square window around each pixel, when counting neiboring pixels
# calculate 2 dimensional histogram of gray_image
v_image_2DHisteq = im2dhist(gray_image, w_neighboring=6, showProgress = True)
# plots 2D-Histogram
[K, _] = v_image_2DHisteq.shape
x = np.outer(np.arange(0, K), np.ones(K))
y = x.copy().T
# ln-ing v_image_2DHisteq makes its details more prominent.
Hist2D_ln = v_image_2DHisteq.copy()
Hist2D_ln[np.where(Hist2D_ln<=0)] = 1e-15
z = np.log(Hist2D_ln)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(x, y, z,cmap='viridis', edgecolor='none')
ax.set_title(f'2D-Histogram of {image_name}')
plt.show()
if __name__ == '__main__': main()
Output
This is a sample image Two dimensional histogram of the sample image
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
im2dhist-0.1.0.5.tar.gz
(387.7 kB
view hashes)
Built Distribution
Close
Hashes for im2dhist-0.1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47fa2edd989a26478f99ecb6b0890429d019445ba8f19da545e45a12384fe627 |
|
MD5 | a82afd272860b85493ef60ba1ba4292b |
|
BLAKE2b-256 | 5f88501768353e2b8ee62d69f19e998ddb7d799aaf51b7d0ac9346576b6179ba |