[![PyPI Latest Release](https://img.shields.io/pypi/v/im2dhist.svg)](https://pypi.org/project/im2dhist/)
[![Package Status](https://img.shields.io/pypi/status/im2dhist.svg)](https://pypi.org/project/im2dhist/)
[![Downloads](https://pepy.tech/badge/im2dhist)](https://pepy.tech/project/im2dhist)
[![License](https://img.shields.io/pypi/l/im2dhist.svg)](https://github.com/Mamdasn/im2dhist/blob/main/LICENSE)
![Repository Size](https://img.shields.io/github/repo-size/mamdasn/im2dhist)
# 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.
![How moving window works](https://raw.githubusercontent.com/Mamdasn/im2dhist/main/assets/how-it-works-window-kernel-title.jpg "How moving window works")
w_neighboring=1 corresponds to a square of 3x3.
## Installation
Run the following to install:
```python
pip install im2dhist
```
## Usage
```python
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
![Plane.jpg Image](https://raw.githubusercontent.com/Mamdasn/im2dhist/main/assets/Plane.jpg "Plane.jpg Image")
Two dimensional histogram of the sample image
![Two Dimensional Histogram](https://raw.githubusercontent.com/Mamdasn/im2dhist/main/assets/Plane-big-2D-Histogram.jpeg "Two Dimensional Histogram")
Raw data
{
"_id": null,
"home_page": "https://github.com/Mamdasn/im2dhist",
"name": "im2dhist",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "python,histogram,imhist,2dhist,hist2d,two dimensional histogram",
"author": "Mamdasan Sabrian",
"author_email": "<reach.s.farhad@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/0b/7c/d4f1f31bd7e77e7031e241497e8d7635bd35d9a067c32aca7157c1f0e8a7/im2dhist-1.0.1.tar.gz",
"platform": null,
"description": "\n[![PyPI Latest Release](https://img.shields.io/pypi/v/im2dhist.svg)](https://pypi.org/project/im2dhist/)\n[![Package Status](https://img.shields.io/pypi/status/im2dhist.svg)](https://pypi.org/project/im2dhist/)\n[![Downloads](https://pepy.tech/badge/im2dhist)](https://pepy.tech/project/im2dhist)\n[![License](https://img.shields.io/pypi/l/im2dhist.svg)](https://github.com/Mamdasn/im2dhist/blob/main/LICENSE)\n![Repository Size](https://img.shields.io/github/repo-size/mamdasn/im2dhist)\n\n\n# im2dhist\nThis 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.\n\n## How it works\nA 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. \n![How moving window works](https://raw.githubusercontent.com/Mamdasn/im2dhist/main/assets/how-it-works-window-kernel-title.jpg \"How moving window works\")\nw_neighboring=1 corresponds to a square of 3x3.\n\n## Installation\n\nRun the following to install:\n\n```python\npip install im2dhist\n```\n\n## Usage\n\n```python\nfrom im2dhist import im2dhist\nimport cv2\nimport numpy as np\nfrom mpl_toolkits import mplot3d\nimport matplotlib.pyplot as plt\n\ndef main():\n image_name = 'Plane.jpg'\n image = cv2.imread(image_name)\n # converts rgb image to gray\n gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n\n # 2*w_neighboring+1 is width of the square window around each pixel, when counting neiboring pixels\n # calculate 2 dimensional histogram of gray_image\n v_image_2DHisteq = im2dhist(gray_image, w_neighboring=6)\n\n # plots 2D-Histogram\n [K, _] = v_image_2DHisteq.shape\n x = np.outer(np.arange(0, K), np.ones(K))\n y = x.copy().T \n # ln-ing v_image_2DHisteq makes its details more prominent.\n Hist2D_ln = v_image_2DHisteq.copy()\n Hist2D_ln[np.where(Hist2D_ln<=0)] = 1e-15\n z = np.log(Hist2D_ln)\n fig = plt.figure()\n ax = plt.axes(projection='3d')\n ax.plot_surface(x, y, z,cmap='viridis', edgecolor='none')\n ax.set_title(f'2D-Histogram of {image_name}')\n plt.show()\nif __name__ == '__main__': main()\n```\n\n## Showcase\nThis is a sample image\n![Plane.jpg Image](https://raw.githubusercontent.com/Mamdasn/im2dhist/main/assets/Plane.jpg \"Plane.jpg Image\")\nTwo dimensional histogram of the sample image\n![Two Dimensional Histogram](https://raw.githubusercontent.com/Mamdasn/im2dhist/main/assets/Plane-big-2D-Histogram.jpeg \"Two Dimensional Histogram\")\n",
"bugtrack_url": null,
"license": "",
"summary": "Calculates two dimensional histogram of a given image.",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/Mamdasn/im2dhist"
},
"split_keywords": [
"python",
"histogram",
"imhist",
"2dhist",
"hist2d",
"two dimensional histogram"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "858c0843640065c4513aa7b5b1138d1f1bd681b5f53388dd33e3a0c0af2d6c2e",
"md5": "ae7a30c5857e7b11d925915287e9c9d5",
"sha256": "ba877bfbab3dff5119196c4ef64d223118237405e81575bacc8b3da6dc8e182c"
},
"downloads": -1,
"filename": "im2dhist-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ae7a30c5857e7b11d925915287e9c9d5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 15367,
"upload_time": "2024-02-17T16:50:27",
"upload_time_iso_8601": "2024-02-17T16:50:27.124043Z",
"url": "https://files.pythonhosted.org/packages/85/8c/0843640065c4513aa7b5b1138d1f1bd681b5f53388dd33e3a0c0af2d6c2e/im2dhist-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0b7cd4f1f31bd7e77e7031e241497e8d7635bd35d9a067c32aca7157c1f0e8a7",
"md5": "670cb47d38af06ccecbf650505fc389e",
"sha256": "04f16e05b4ec8f4cf3f73c6092fbe761cbe5195729633a0c5d5d1f6eff491da6"
},
"downloads": -1,
"filename": "im2dhist-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "670cb47d38af06ccecbf650505fc389e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 507570,
"upload_time": "2024-02-17T16:50:29",
"upload_time_iso_8601": "2024-02-17T16:50:29.524397Z",
"url": "https://files.pythonhosted.org/packages/0b/7c/d4f1f31bd7e77e7031e241497e8d7635bd35d9a067c32aca7157c1f0e8a7/im2dhist-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-17 16:50:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Mamdasn",
"github_project": "im2dhist",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "im2dhist"
}