{"id":17675565,"url":"https://github.com/ernanej/ruby-edge-detection-threads","last_synced_at":"2025-03-30T17:14:47.687Z","repository":{"id":199959779,"uuid":"704189414","full_name":"ErnaneJ/ruby-edge-detection-threads","owner":"ErnaneJ","description":"Edge and Relief Detection in Images with MiniMagic and Ruby Threads.","archived":false,"fork":false,"pushed_at":"2023-10-12T18:30:51.000Z","size":5801,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T18:59:36.719Z","etag":null,"topics":["image-processing","ruby","threads"],"latest_commit_sha":null,"homepage":"https://ernanej.github.io/posts/deteccao-de-bordas-e-relevos-em-imagens-com-minimagic-e-ruby-threads/","language":"Ruby","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/ErnaneJ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-12T18:15:29.000Z","updated_at":"2024-04-22T02:23:52.000Z","dependencies_parsed_at":"2023-10-14T19:46:39.093Z","dependency_job_id":null,"html_url":"https://github.com/ErnaneJ/ruby-edge-detection-threads","commit_stats":null,"previous_names":["ernanej/ruby-edge-detection-threads"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErnaneJ%2Fruby-edge-detection-threads","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErnaneJ%2Fruby-edge-detection-threads/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErnaneJ%2Fruby-edge-detection-threads/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ErnaneJ%2Fruby-edge-detection-threads/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ErnaneJ","download_url":"https://codeload.github.com/ErnaneJ/ruby-edge-detection-threads/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246351017,"owners_count":20763232,"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":["image-processing","ruby","threads"],"created_at":"2024-10-24T07:22:45.911Z","updated_at":"2025-03-30T17:14:47.651Z","avatar_url":"https://github.com/ErnaneJ.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Edge and Relief Detection in Images 🌄\n\nThe field of digital image processing and analysis has made remarkable strides in the early years of the 21st century. This progress has been fueled by a fervor for research and the development of technologies applicable to various domains, including medicine, biology, industrial automation, and remote sensing.\n\n## 📸 Digital Image Processing\n\nDigital image processing involves a suite of techniques for capturing, representing, and transforming images with the help of computers. This approach enables information extraction, structural enhancement, and automatic interpretation of images through computer programs. It enhances both human understanding and computational analysis of images.\n\n## 🔍 Edge Detection\n\nEdge detection is a critical aspect of image processing, facilitating the identification of significant transitions in pixel intensities and enabling object segmentation and analysis.\n\nWe employ convolution operations to detect edges in an M by N matrix image in both x and y directions, using masks as operators applied to pixels of interest and their neighbors. Several operators, such as the Prewitt operators, can be utilized for this task. The matrices like the ones below are instrumental:\n\n```\nGx = |-1  0  1| ; Gy = |-1 -1 -1|\n     |-1  0  1| ;      | 0  0  0|\n     |-1  0  1| ;      | 1  1  1|\n```\n\nThese matrices compute intensity variations in the x and y directions, allowing us to pinpoint edges.\n\nGx and Gy represent the masks used for edge detection in the x and y directions of the digital image. By applying these masks, we obtain separate edge images in both directions. The final segmented image is produced by amalgamating information from these two edge images.\n\n![m](./doc/m.png)\n\n## 🧮 Pseudocode for implementation\n\nGiven a grayscale image I with dimensions M × N, we perform the following:\n\n  - We create an image (array) M × N, Gx, with all elements initialized to 0.\n  - We create an image (array) M × N, Gy, with all elements initialized to 0.\n  - We create an image (array) M × N, G, which can initially be set with all elements equal to zero.\n\nThe pseudocode for the calculations is outlined in the code block below.\n\n```\n# Calculating edge information\nFor i ranging from 1 to M-2\n  For j ranging from 1 to N-2\n    # Calculation of Gx...\n    Gx(i, j) = [ I(i+1, j-1) + I(i+1, j) + I(i+1, j+1) ] - [ I(i-1, j-1) + I(i-1, j) + I(i-1, j+1) ]\n    # Clamping...\n    If Gx(i, j) \u003c 0, Gx(i, j) = 0;\n    If Gx(i, j) \u003e 255, Gx(i, j) = 255;\n  end-for\nend-for\n\n# Generating output image...\nFor i ranging from 0 to M-1\n  For j ranging from 0 to N-1\n    G(i, j) = Gx(i, j) + Gy(i, j)\n    If G(i, j) \u003e 255, G(i, j) = 255\n  end-for\nend-for\n```\n\n## 🛠️ Project\n\nThis project involves developing a Ruby program that utilizes threads to create two threads, one for obtaining the edge image in the x-direction and the other in the y-direction from an existing image. The main thread opens the input image, represents it using a suitable array, and then spawns two threads for calculating the edge images Gx and Gy. After their tasks are complete, the parent thread reads the two resulting image arrays to calculate the output image G.\n\n## 🚀 Development\n\n- The [main program](./src/main.rb) processes four distinct images located in the [assets folder](./assets).\n- The project's core class is [ImageProcessing](./src/models/image_processing.rb), tailored exclusively for this problem. The code contains detailed information about methods and usage.\n- The only library/gem used in this project is MiniMagick, as indicated in the Gemfile.\n- No external libraries were required for implementing threads, as Ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux] natively includes the [Thread class](https://ruby-doc.org/core-2.5.1/Thread.html).\n\n## 📊 Results\n\n| Original                   | Processed                        |\n|:--------------------------:|:--------------------------------:|\n|![Coins](./assets/coins.png)|![Coin](./assets/coins_output.png)|\n|![Dog](./assets/dog.png)    |![Dog](./assets/dog_output.png)   |\n|![Lena](./assets/lena.jpg)  |![Lena](./assets/lena_output.jpg) |\n|![UFRN](./assets/ufrn.png)  |![UFRN](./assets/ufrn_output.png) |\n\n## 📚 References\n\n- [Thread Ruby](https://ruby-doc.org/core-2.5.1/Thread.html)\n- [MiniMagic Gem](https://rubygems.org/gems/mini_magick/versions/4.5.1?locale=en)\n- [Ruby doc 3.2.0](https://ruby-doc.org/3.2.0/)\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  📚 DCA0108 - Operating Systems (2023.1) 🎓 \u003cbr/\u003e\n  Federal University of Rio Grande do Norte - Department of Computer and Automation Engineering (DCA). 🏛️\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fernanej%2Fruby-edge-detection-threads","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fernanej%2Fruby-edge-detection-threads","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fernanej%2Fruby-edge-detection-threads/lists"}