im2dhist
This small piece of code is intended to help researchers, especially in field of image processing, to easily calculate two dimensional histogram of a given image.
How it works
A moving window of WxW moves through out the given image, and as its center places on each pixel, number of encounters with same and other brightness intensities is counted seperately. This package basically outputs a normalized two dimensional numpy array of brightness intensity encounters.
w_neighboring=1 corresponds to a square of 3x3.
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)
# 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()
Showcase
This is a sample image
Two dimensional histogram of the sample image
Metadata
Release files for im2dhist 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| im2dhist-1.0.1.tar.gz | 507.6 kB | Without provenance | Details for im2dhist-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| im2dhist-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for im2dhist-1.0.1-py3-none-any.whl |
Total release size: 522.9 kB
Release files / im2dhist-1.0.1.tar.gz
| Download URL | im2dhist-1.0.1.tar.gz |
|---|---|
| Size | 507.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04f16e05b4ec8f4cf3f73c6092fbe761cbe5195729633a0c5d5d1f6eff491da6
|
|
BLAKE2b-256 checksum How to use checksums |
0b7cd4f1f31bd7e77e7031e241497e8d7635bd35d9a067c32aca7157c1f0e8a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Release files / im2dhist-1.0.1-py3-none-any.whl
| Download URL | im2dhist-1.0.1-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba877bfbab3dff5119196c4ef64d223118237405e81575bacc8b3da6dc8e182c
|
|
BLAKE2b-256 checksum How to use checksums |
858c0843640065c4513aa7b5b1138d1f1bd681b5f53388dd33e3a0c0af2d6c2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Security for im2dhist 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.