{"id":13747211,"url":"https://github.com/nicolashahn/diffimg","last_synced_at":"2025-05-09T08:32:00.342Z","repository":{"id":46321875,"uuid":"55076609","full_name":"nicolashahn/diffimg","owner":"nicolashahn","description":"Differentiate images in python - get a ratio or percentage difference, and generate a diff image","archived":false,"fork":false,"pushed_at":"2023-05-18T11:30:36.000Z","size":3349,"stargazers_count":213,"open_issues_count":3,"forks_count":26,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-29T05:17:16.724Z","etag":null,"topics":["diffing","image-processing","python","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nicolashahn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-30T15:54:15.000Z","updated_at":"2024-10-15T00:30:14.000Z","dependencies_parsed_at":"2024-06-18T17:18:05.866Z","dependency_job_id":"c8f0db01-4abe-4da9-ac39-b8beee6d87da","html_url":"https://github.com/nicolashahn/diffimg","commit_stats":{"total_commits":48,"total_committers":2,"mean_commits":24.0,"dds":0.02083333333333337,"last_synced_commit":"b82f0bb416f100f9105ccccf1995872b29302461"},"previous_names":["nicolashahn/python-image-diff"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolashahn%2Fdiffimg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolashahn%2Fdiffimg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolashahn%2Fdiffimg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicolashahn%2Fdiffimg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicolashahn","download_url":"https://codeload.github.com/nicolashahn/diffimg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224842626,"owners_count":17379001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diffing","image-processing","python","testing-tools"],"created_at":"2024-08-03T06:01:20.409Z","updated_at":"2024-11-15T20:31:14.433Z","avatar_url":"https://github.com/nicolashahn.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# diffimg\nGet the % difference in images using PIL's histogram + generate a diff image. Images\nshould have the same color channels (for example, RGB vs RGBA). If the image dimensions\ndiffer, the 2nd image will be resized to match the first before calculating the diff.\n\n[![PyPI version](https://badge.fury.io/py/diffimg.svg)](https://badge.fury.io/py/diffimg)\n\n\n### Installation\n\nNow available from PyPi: `pip install diffimg`\n\n### Usage\n\n```\n\u003e\u003e\u003e from diffimg import diff\n\u003e\u003e\u003e diff('mario-circle-cs.png', 'mario-circle-node.png')\n0.007319618135968298\n```\nThe [very simple](/diffimg/diff.py#L12) `diff` function returns a raw ratio instead of a\n% by default.\n\n```\ndiff(im1_file, \n     im2_file, \n     delete_diff_file=False, \n     diff_img_file=DIFF_IMG_FILE\n     ignore_alpha=False)\n```\n`im1_file, im2_file`: filenames of images to diff.\n\n`delete_diff_file`: a file showing the differing areas of the two images is generated in\norder to measure the diff ratio with the same dimensions as the first image. Setting\nthis to `True` removes it after calculating the ratio.\n\n`diff_img_file`: filename for the diff image file. Defaults to `diff_img.png`\n(regardless of inputed file's types).\n\n`ignore_alpha`: ignore the alpha channel for the ratio and if applicable, sets the alpha\nof the diff image to fully opaque.\n\n### As command line tool\n\n`python -m diffimg image1 image2 [-r/--ratio] [-d/--delete] [-f/--filename DIFF_IMG_FILE]`\n\n`--ratio` outputs a number between 0 and 1 instead of the default `Images differ by X%`.\n\n`--delete` removes the diff file after retrieving ratio/percentage.\n\n`--filename` specifies a filename to save the diff image under. Must use a valid extension.\n\n`--ignore-alpha` ignore the alpha channel.\n\n### Tests\n\n```\n$ ./test.py\n......\n----------------------------------------------------------------------\nRan 6 tests in 0.320s\n\nOK\n```\n\n### Formula \n\nThe difference is defined by the average % difference between each of the channels\n(R,G,B,A?) at each pair of pixels A\u003csub\u003exy\u003c/sub\u003e, B\u003csub\u003exy\u003c/sub\u003e at the same coordinates\nin each of the two images (why they need to be the same size), averaged over all pairs\nof pixels. \n\nFor example, compare two 1x1 images _A_ and _B_ (a trivial example, \u003e1 pixels would have\nanother step to find the average of all pixels):\n\n_A_\u003csub\u003e1,1\u003c/sub\u003e = RGB(255,0,0) _(pure red)_\n\n_B_\u003csub\u003e1,1\u003c/sub\u003e = RGB(100,0,0) _(dark red)_\n\n((255-100)/255 + (0/0)/255 + (0/0)/255))/3 = (155/255)/3 = 0.202614379\n\nSo these two 1x1 images differ by __20.2614379%__ according to this formula.\n\n## Sample image 1\n![Alt text](/images/mario-circle-cs.png \"Image 1\")\n\n## Sample image 2\n![Alt text](/images/mario-circle-node.png \"Image 2\")\n\n## Resulting diff image\n![Alt text](/images/diff_img.png \"Difference Image\")\n\n## Difference percentage output\n`Images differ by 0.731961813597%`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolashahn%2Fdiffimg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicolashahn%2Fdiffimg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicolashahn%2Fdiffimg/lists"}