# Parallelized image resizing function using OpenCV and multiprocessing
## pip install multicv2resize
### Tested against Python 3.11 / Windows 10
```python
Parallelized image resizing function using OpenCV and multiprocessing.
This function utilizes the `multiprocnomain` library for parallelizing the resizing process of a batch of images.
The resizing parameters for each image in the batch are specified in a list of dictionaries,
allowing for flexibility in resizing options.
Parameters:
- pics (list): A list of dictionaries, each containing the following keys:
- 'img' (Any): Accepts almost any image format
- 'width' (int, optional): The target width of the resized image. If None, the original width is maintained. - IMPORTANT: (pass either width, height, width and height, or percentage)
- 'height' (int, optional): The target height of the resized image. If None, the original height is maintained. - IMPORTANT: (pass either width, height, width and height, or percentage)
- 'percent' (int, optional): The percentage by which to scale the image. - IMPORTANT: (pass either width, height, width and height, or percentage)
- 'interpolation' (int, optional): The interpolation method to use during resizing.
Defaults to cv2.INTER_AREA.
- processes (int, optional): The number of parallel processes to use for resizing. Defaults to 5.
- chunks (int, optional): The number of chunks to divide the resizing tasks into for better load balancing. Defaults to 1.
- print_stderr (bool, optional): If True, prints stderr messages during the resizing process. Defaults to True.
- print_stdout (bool, optional): If True, prints stdout messages during the resizing process. Defaults to False.
Returns:
- dict: A dictionary containing resized images corresponding to the input batch. The keys are generated based on the input image paths.
Example:
pics0 = [{'img':r"C:\Users\hansc\Pictures\cgea.png",'width':None,'height':None,'percent':percentage,'interpolation':cv2.INTER_AREA} for percentage in range(50,150,1)]
pics1 = [{'img':r"C:\Users\hansc\Pictures\cgea.png",'width':100+addwidth,'height':100,'percent':None,'interpolation':cv2.INTER_AREA} for addwidth in range(50,150,1)]
pics=pics0+pics1
pic=resize_image(pics,processes=5,chunks=1,print_stderr=True, print_stdout=False)
for k, v in pic.items():
cv2.imwrite(rf'C:\resi\{k}.png', v)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/multicv2resize",
"name": "multicv2resize",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "multiprocessing,resize,image",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/93/35/34eb347bef93d1a6c54a63005052474b918538f04109f208d20d2a461c95/multicv2resize-0.10.tar.gz",
"platform": null,
"description": "\r\n# Parallelized image resizing function using OpenCV and multiprocessing\r\n\r\n## pip install multicv2resize\r\n\r\n### Tested against Python 3.11 / Windows 10\r\n\r\n```python\r\n\r\nParallelized image resizing function using OpenCV and multiprocessing.\r\n\r\nThis function utilizes the `multiprocnomain` library for parallelizing the resizing process of a batch of images.\r\nThe resizing parameters for each image in the batch are specified in a list of dictionaries,\r\nallowing for flexibility in resizing options.\r\n\r\nParameters:\r\n\t- pics (list): A list of dictionaries, each containing the following keys:\r\n\t\t- 'img' (Any): Accepts almost any image format\r\n\t\t- 'width' (int, optional): The target width of the resized image. If None, the original width is maintained. - IMPORTANT: (pass either width, height, width and height, or percentage)\r\n\t\t- 'height' (int, optional): The target height of the resized image. If None, the original height is maintained. - IMPORTANT: (pass either width, height, width and height, or percentage)\r\n\t\t- 'percent' (int, optional): The percentage by which to scale the image. - IMPORTANT: (pass either width, height, width and height, or percentage)\r\n\t\t- 'interpolation' (int, optional): The interpolation method to use during resizing.\r\n\t\t Defaults to cv2.INTER_AREA.\r\n\r\n\t- processes (int, optional): The number of parallel processes to use for resizing. Defaults to 5.\r\n\r\n\t- chunks (int, optional): The number of chunks to divide the resizing tasks into for better load balancing. Defaults to 1.\r\n\r\n\t- print_stderr (bool, optional): If True, prints stderr messages during the resizing process. Defaults to True.\r\n\r\n\t- print_stdout (bool, optional): If True, prints stdout messages during the resizing process. Defaults to False.\r\n\r\nReturns:\r\n\t- dict: A dictionary containing resized images corresponding to the input batch. The keys are generated based on the input image paths.\r\n\r\nExample:\r\n\r\n\tpics0 = [{'img':r\"C:\\Users\\hansc\\Pictures\\cgea.png\",'width':None,'height':None,'percent':percentage,'interpolation':cv2.INTER_AREA} for percentage in range(50,150,1)]\r\n\tpics1 = [{'img':r\"C:\\Users\\hansc\\Pictures\\cgea.png\",'width':100+addwidth,'height':100,'percent':None,'interpolation':cv2.INTER_AREA} for addwidth in range(50,150,1)]\r\n\tpics=pics0+pics1\r\n\r\n\tpic=resize_image(pics,processes=5,chunks=1,print_stderr=True, print_stdout=False)\r\n\tfor k, v in pic.items():\r\n\t\tcv2.imwrite(rf'C:\\resi\\{k}.png', v)\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Parallelized image resizing function using OpenCV and multiprocessing",
"version": "0.10",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/multicv2resize"
},
"split_keywords": [
"multiprocessing",
"resize",
"image"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0eeba6cd269ca9b3af87e991890778d21a68af42f543a77e8f9815fdff20f90",
"md5": "9e58dd0c4d983643cba1a6cbf93f866a",
"sha256": "49563ab3719ce4f7462763063f39fd918a7e1c5149ddc7a99b71f471bb1219bd"
},
"downloads": -1,
"filename": "multicv2resize-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9e58dd0c4d983643cba1a6cbf93f866a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 57425,
"upload_time": "2023-11-12T21:36:41",
"upload_time_iso_8601": "2023-11-12T21:36:41.145564Z",
"url": "https://files.pythonhosted.org/packages/f0/ee/ba6cd269ca9b3af87e991890778d21a68af42f543a77e8f9815fdff20f90/multicv2resize-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "933534eb347bef93d1a6c54a63005052474b918538f04109f208d20d2a461c95",
"md5": "9ec2f0e65f60304ba448a6975f145f45",
"sha256": "0a973c2443fdb45b34c58053cf6fec44a831551572e224e7f763cf0c9dc9db51"
},
"downloads": -1,
"filename": "multicv2resize-0.10.tar.gz",
"has_sig": false,
"md5_digest": "9ec2f0e65f60304ba448a6975f145f45",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 56090,
"upload_time": "2023-11-12T21:36:43",
"upload_time_iso_8601": "2023-11-12T21:36:43.433559Z",
"url": "https://files.pythonhosted.org/packages/93/35/34eb347bef93d1a6c54a63005052474b918538f04109f208d20d2a461c95/multicv2resize-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-12 21:36:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "multicv2resize",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "a_cv2_easy_resize",
"specs": []
},
{
"name": "a_cv_imwrite_imread_plus",
"specs": []
},
{
"name": "multiprocnomain",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "opencv_python",
"specs": []
}
],
"lcname": "multicv2resize"
}