{"id":13314259,"url":"https://github.com/dario-marvin/ImageProcessing-KernelConvolution","last_synced_at":"2025-03-10T20:33:36.158Z","repository":{"id":243018775,"uuid":"148841117","full_name":"dario-marvin/ImageProcessing-KernelConvolution","owner":"dario-marvin","description":null,"archived":false,"fork":false,"pushed_at":"2019-06-18T08:21:16.000Z","size":592,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-29T19:06:02.904Z","etag":null,"topics":["c-plus-plus","convolution","image-processing","kernel","python"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dario-marvin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-09-14T20:58:00.000Z","updated_at":"2019-06-18T08:21:18.000Z","dependencies_parsed_at":"2024-06-06T09:21:17.399Z","dependency_job_id":null,"html_url":"https://github.com/dario-marvin/ImageProcessing-KernelConvolution","commit_stats":null,"previous_names":["dario-marvin/imageprocessing-kernelconvolution"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-marvin%2FImageProcessing-KernelConvolution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-marvin%2FImageProcessing-KernelConvolution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-marvin%2FImageProcessing-KernelConvolution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-marvin%2FImageProcessing-KernelConvolution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dario-marvin","download_url":"https://codeload.github.com/dario-marvin/ImageProcessing-KernelConvolution/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242922082,"owners_count":20207145,"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":["c-plus-plus","convolution","image-processing","kernel","python"],"created_at":"2024-07-29T18:11:27.643Z","updated_at":"2025-03-10T20:33:35.865Z","avatar_url":"https://github.com/dario-marvin.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Image Processing: Kernel Convolution\n\n## Kernel convolution\nThe idea behind image processing with kernel convolution is to use a special matricial operation called _convolution_ which takes as input two matrices: a matrix of weights, which is the kernel, and the matrix of the RGB values of our image (in the range [0, 255]). The output will be a new image with pixel values modified depending on the kernel used.  \nFor instance, supposing we use a 3x3 kernel matrix, the pixel RGB value at position [2,2] in the modified image will be calculates as  \n\u003cp align=\"center\"\u003e\n \u003cimg src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/LaTex/formula1.png\"\u003e\n\u003c/p\u003e\nFor edge and corner pixels, the idea is to locally overextend the image using the available pixels. For example the RGB value at position [1,1] is\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/LaTex/formula2.png\"\u003e\n\u003c/p\u003e\n\n## Examples and applications\n### Simple blurring\n\nProbably the most evident example of this technique is blurring. To achieve this effect, we use a Kernel matrix given by\n\u003cp align=\"center\"\u003e\n  \u003cimg width=200 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/LaTex/blur.png\"\u003e\n\u003c/p\u003e\nwhich means that every pixel is the calibrated mean of the 8 neighbours surrounding it.  \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/rubik_Blur.jpg\"\u003e\n\u003c/p\u003e\n\n### Gaussian blurring\n\nThe gaussian blurring effect is obtained by employing a matrix where the values are not constant as in the previous example, but are chosen according to the Gaussian distribution with regard to the vertical and horizontal distance between each surrounding pixel and the central one. In this example we consider a 13x13 kernel matrix, thus the image appears more \"smoothed\" than the preceeding one.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/rubik_Gaussian_blur.jpg\"\u003e\n\u003c/p\u003e\n\n### Edge detection\n\nWhen performing edge detection, we want to highlight those pixels whose neighbours are not regular. Or, equivalently, we want to dampen those pixels who are equals in value to the immediately close ones. Thus we consider a Kernel matrix given by\n\u003cp align=\"center\"\u003e\n  \u003cimg width=200 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/LaTex/edgeDetect.png\"\u003e\n\u003c/p\u003e\nNotice that by doing so, if the central pixel and the 8 surrounding ones have all the same value, the resulting pixel will have value 0, hence it will be black.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/rubik_Edge_detection.jpg\"\u003e\n\u003c/p\u003e\n\n### Sharpen\nSharpening effects are applied by enhancing the constrast with pixels on the sides, thus we use a kernel matrix given by \n\u003cp align=\"center\"\u003e\n  \u003cimg width=200 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/LaTex/sharpen.png\"\u003e\n\u003c/p\u003e\n\nWe apply this effect on a fractured tibia x-ray image and on a brain tumor MRI. Both images where found on Google. \n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=500 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/tibia_Sharpen.jpg\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=500 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/brain_Sharpen.jpg\"\u003e\n\u003c/p\u003e\n\n### Emboss\nEmbossing is a particular processing used to give a 2D image an idea of tridimensionality. The kernel matrix\n\u003cp align=\"center\"\u003e\n  \u003cimg width=200 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/LaTex/emboss.png\"\u003e\n\u003c/p\u003e\nensures that a border separanting two differently colored areas (top-left to bottom-right) will be particularly highlighted depending on the pixels.  \nFor instance, when we go from a top darker area to a bottom lighter area, the border is highlighted in white, while the opposite occurs if you invert the colors. Thus we obtain a 3D effect in a given direction.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=500 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/tibia_Emboss.jpg\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=500 src=\"https://github.com/dario-marvin/ImageProcessing-KernelConvolution/blob/master/Images/brain_Emboss.jpg\"\u003e\n\u003c/p\u003e\n\n## How to compile and execute the files\n#### Only tested in Ubuntu 16.04, not tested for other systems or distributions\nDownload the files `image_convolution.py` and `kernel_application.cc` in the same folder where you also have the image you want to process.  \nAt line 7 of `image_convolution.py` insert the name of your image and choose one of the kernel at lines 22-28.   \nThen save your changes, open a terminal and run the command\n```\npython3 image_convolution.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdario-marvin%2FImageProcessing-KernelConvolution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdario-marvin%2FImageProcessing-KernelConvolution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdario-marvin%2FImageProcessing-KernelConvolution/lists"}