{"id":18881536,"url":"https://github.com/azlinrusnan/image_analysis_using_r_and_imager","last_synced_at":"2026-02-21T03:30:16.209Z","repository":{"id":244334712,"uuid":"814943822","full_name":"AzlinRusnan/Image_Analysis_Using_R_and_Imager","owner":"AzlinRusnan","description":"This project demonstrates various image processing techniques using the imager package in R. ","archived":false,"fork":false,"pushed_at":"2024-06-14T03:55:44.000Z","size":4427,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T03:27:40.166Z","etag":null,"topics":["image","imager","r"],"latest_commit_sha":null,"homepage":"","language":"R","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/AzlinRusnan.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":"2024-06-14T03:16:42.000Z","updated_at":"2024-06-14T03:57:15.000Z","dependencies_parsed_at":"2024-06-14T04:30:01.793Z","dependency_job_id":"6bd192fa-4c54-4372-8960-671ff97233da","html_url":"https://github.com/AzlinRusnan/Image_Analysis_Using_R_and_Imager","commit_stats":null,"previous_names":["azlinrusnan/image_analysis_using_r_and_imager"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzlinRusnan%2FImage_Analysis_Using_R_and_Imager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzlinRusnan%2FImage_Analysis_Using_R_and_Imager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzlinRusnan%2FImage_Analysis_Using_R_and_Imager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzlinRusnan%2FImage_Analysis_Using_R_and_Imager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AzlinRusnan","download_url":"https://codeload.github.com/AzlinRusnan/Image_Analysis_Using_R_and_Imager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239850447,"owners_count":19707348,"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","imager","r"],"created_at":"2024-11-08T06:49:54.982Z","updated_at":"2025-02-20T13:48:32.081Z","avatar_url":"https://github.com/AzlinRusnan.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cdiv align=\"center\"\u003e📸 Image Analysis Using R and Imager 📸\u003c/div\u003e\n\nWelcome to the Image Analysis repository! This project demonstrates various image processing techniques using the imager package in R. The main focus is on analyzing two specific images (Person1.jpg and Person2.jpg) with a series of image processing tasks including edge detection, image splitting and concatenating, filtering, blurring and sharpening, segmentation, histogram equalization, and morphological operations.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Getting Started](#getting-started)\n- [Image Analysis Techniques](#image-analysis-techniques)\n  - [Edge Detection](#edge-detection)\n  - [Splitting \u0026 Concatenating Image](#splitting--concatenating-image)\n  - [Filtering Image](#filtering-image)\n  - [Blurry \u0026 Sharpen](#blurry--sharpen)\n  - [Segmentation](#segmentation)\n  - [Histogram Equalization](#histogram-equalization)\n  - [Morphological Operations](#morphological-operations)\n- [Conclusion](#conclusion)\n\n## Introduction\n\nThis project is part of an assignment for the course STQD6114 Unstructured Data. It involves analyzing two images using various image processing techniques. The goal is to apply these techniques and visualize the results to understand their effects on the images.\n\n## Getting Started\n\n### Prerequisites\n\n- R (version 4.0 or higher)\n- RStudio (optional, but recommended)\n- `imager` package\n\n### Installation\n\n1. Install R from [CRAN](https://cran.r-project.org/).\n2. Install RStudio from [RStudio](https://www.rstudio.com/).\n3. Install the `imager` package by running the following command in R:\n\n   ```R\n   install.packages(\"imager\")\n\n## Image Analysis Techniques\n\n- ### Original Images\n\n### 1.  Person 1\n\n![Person_1](images/Person1.jpg)\n\n### 2.  Person 2\n\n![Person_2](images/Person2.jpg)\n\n- ### Edge Detection\n\nEdge detection is used to identify the boundaries within an image. This is achieved by computing image gradients and plotting the gradient magnitudes.\n\n```R\n# i. Edge detection\n\n# Compute image gradients\ngrad_person1 \u003c- imgradient(person1, \"xy\")\ngrad_person2 \u003c- imgradient(person2, \"xy\")\n\n# Compute gradient magnitude\ngrad_mag_person1 \u003c- sqrt(grad_person1$x^2 + grad_person1$y^2)\ngrad_mag_person2 \u003c- sqrt(grad_person2$x^2 + grad_person2$y^2)\n\n# Plot the original and gradient magnitude images\npar(mfrow = c(2, 2))\nplot(person1, main = \"Original person1\")\nplot(grad_mag_person1, main = \"Gradient Magnitude of Person 1\")\n\nplot(person2, main = \"Original Person 2\")\nplot(grad_mag_person2, main = \"Gradient Magnitude of Person 2\")\n```\n![Edge_Detection](images/adgedetec.png)\n\n- ### Splitting \u0026 Concatenating Image\n\nThe images are split into top and bottom halves. These halves are then concatenated in different combinations to create new images.\n\n```R\n# ii. Splitting \u0026 concatenating image\n\n# Get dimensions\nheight1 \u003c- dim(person1)[1]\nwidth1 \u003c- dim(person1)[2]\nheight2 \u003c- dim(person2)[1]\nwidth2 \u003c- dim(person2)[2]\n\n# Split person1\nperson1_top \u003c- subim(person1, y \u003c= height1 / 2)\nperson1_bottom \u003c- subim(person1, y \u003e height1 / 2)\n\n# Split person2\nperson2_top \u003c- subim(person2, y \u003c= height2 / 2)\nperson2_bottom \u003c- subim(person2, y \u003e height2 / 2)\n\n# Concatenate the segments\n# Here we concatenate the top half of person1 with the bottom half of person2 and vice versa\nconcat_image1 \u003c- imappend(list(person1_top, person2_bottom), axis = \"y\")\nconcat_image2 \u003c- imappend(list(person2_top, person1_bottom), axis = \"y\")\n\n# Plot the concatenated images\npar(mfrow = c(1, 2))\nplot(concat_image1, main = \"Person 1 Top + Person 2 Bottom\")\nplot(concat_image2, main = \"Person 2 Top + Person 1 Bottom\")\n```\n![Split_Conc](images/splitC.png)\n\n- ### Filtering Image\n\nFiltering involves applying specific filters to the images to enhance or extract particular features. Here, Deriche and Vanvliet filters are applied to grayscale images.\n\n```R\n# iii. Filtering image\n\n# Convert images to grayscale\nperson1_gray \u003c- grayscale(person1)\nperson2_gray \u003c- grayscale(person2)\n\n# Apply Deriche and Vanvliet filters\nderiche_person1 \u003c- deriche(person1_gray, sigma = 4, order = 2, axis = \"y\")\nvanvliet_person1 \u003c- vanvliet(person1_gray, sigma = 4, order = 2, axis = \"y\")\n\nderiche_person2 \u003c- deriche(person2_gray, sigma = 4, order = 2, axis = \"y\")\nvanvliet_person2 \u003c- vanvliet(person2_gray, sigma = 4, order = 2, axis = \"y\")\n\n# Plot the original and filtered images\npar(mfrow = c(2, 2))\nplot(person1, main = \"Original Person 1\")\nplot(deriche_person1, main = \"Deriche Filtered Person 1\")\nplot(vanvliet_person1, main = \"Vanvliet Filtered Person 1\")\n\npar(mfrow = c(2, 2))\nplot(person2, main = \"Original Person 2\")\nplot(deriche_person2, main = \"Deriche Filtered Person 2\")\nplot(vanvliet_person2, main = \"Vanvliet Filtered Person 2\")\n```\n![Fill1](images/FilterP1.png)\n##############\n![Fill2](images/FilterP2.png)\n\n- ### Blurry \u0026 Sharpen\n\nBlurring and sharpening are used to smoothen and enhance image details, respectively. Gaussian blur is applied for noticeable blurring, and a sharpening kernel is used to enhance the details.\n\n```R\n# iv. Blurry \u0026 sharpen\n\n# Apply Gaussian filter with increased sigma for noticeable blurring\ngaussian_person1 \u003c- isoblur(person1, sigma = 10)\ngaussian_person2 \u003c- isoblur(person2, sigma = 10)\n\n# Define a sharpening kernel\nsharpening_kernel \u003c- array(c(-1, -1, -1,\n                             -1,  9, -1,\n                             -1, -1, -1), c(3, 3, 1, 1))\n\n# Apply sharpening filter using convolve function\nsharpen_person1 \u003c- imager::convolve(person1, sharpening_kernel)\nsharpen_person2 \u003c- imager::convolve(person2, sharpening_kernel)\n\n# Plot the original, blurred, and sharpened images\npar(mfrow = c(2, 3))\nplot(person1, main = \"Original Person 1\")\nplot(gaussian_person1, main = \"Gaussian Blurred Person 1\")\nplot(sharpen_person1, main = \"Sharpened Person 1\")\n\nplot(person2, main = \"Original Person 2\")\nplot(gaussian_person2, main = \"Gaussian Blurred Person 2\")\nplot(sharpen_person2, main = \"Sharpened Person 2\")\n```\n![BS](images/BlurSharp.png)\n\n- ### Segmentation\n\nSegmentation is the process of partitioning an image into distinct regions. Thresholding is used for this purpose, creating binary segmented images.\n\n```R\n# v. Segmentation\n\n# Apply thresholding for segmentation\nthreshold \u003c- 0.5\nsegmented_person1 \u003c- person1 \u003e threshold\nsegmented_person2 \u003c- person2 \u003e threshold\n\n# Plot the original and segmented images\npar(mfrow = c(2, 2))\nplot(person1, main = \"Original Person 1\")\nplot(segmented_person1, main = \"Segmented Person 1\")\n\nplot(person2, main = \"Original Person 2\")\nplot(segmented_person2, main = \"Segmented Person 2\")\n```\n![Seg](images/segmented.png)\n- ### Histogram Equalization\n\nHistogram equalization improves the contrast of images. This technique spreads out the most frequent intensity values, enhancing the visibility of details.\n\n```R\n# Histogram Equalization\n\n# Function for histogram equalization\nhist_equalize \u003c- function(image) {\n  hist \u003c- hist(image, plot = FALSE)$counts\n  cdf \u003c- cumsum(hist) / sum(hist)\n  equalized \u003c- as.numeric(approx(x = seq(0, 1, length.out = length(hist)), y = cdf, xout = image)$y)\n  dim(equalized) \u003c- dim(image)\n  return(as.cimg(equalized))\n}\n\n# Perform histogram equalization\nperson1_eq \u003c- hist_equalize(person1)\nperson2_eq \u003c- hist_equalize(person2)\n\n# Plot the original and equalized images\npar(mfrow = c(2, 2))\n\nplot(person1, main = \"Original Person 1\")\nplot(person1_eq, main = \"Equalized Person 1\")\n\nplot(person2, main = \"Original Person 2\")\nplot(person2_eq, main = \"Equalized Person 2\")\n\n```\n![Eq](images/Eq.png)\n- ### Morphological Operations\n\nMorphological operations like erosion, dilation, opening, and closing are used to modify the shapes within an image. These operations are applied using a disk-shaped structuring element.\n\n```R\n# vii. Morphological operations\n\n# Convert to grayscale\n#person1_gray \u003c- grayscale(person1)\n#person2_gray \u003c- grayscale(person2)\n\n# Define the structuring element (disk shape)\nselem \u003c- imfill(11, 11, val = 1) %\u003e% as.cimg() %\u003e% dilate_square(5)\n\n# Apply erosion\neroded_person1 \u003c- erode(person1, selem)\neroded_person2 \u003c- erode(person2, selem)\n\n# Apply dilation\ndilated_person1 \u003c- dilate(person1, selem)\ndilated_person2 \u003c- dilate(person2, selem)\n\n# Apply opening\nopened_person1 \u003c- erode(person1, selem) %\u003e% dilate(selem)\nopened_person2 \u003c- erode(person2, selem) %\u003e% dilate(selem)\n\n# Apply closing\nclosed_person1 \u003c- dilate(person1, selem) %\u003e% erode(selem)\nclosed_person2 \u003c- dilate(person2, selem) %\u003e% erode(selem)\n\n# Plotting the results\npar(mfrow = c(1, 2))\nplot(person1, main = \"Original Person 1\")\nplot(eroded_person1, main = \"Eroded Person 1\")\n\npar(mfrow = c(1, 2))\nplot(person2, main = \"Original Person 2\")\nplot(eroded_person2, main = \"Eroded Person 2\")\n\npar(mfrow = c(1, 2))\nplot(person1, main = \"Original Person 1\")\nplot(dilated_person1, main = \"Dilated Person 1\")\n\npar(mfrow = c(1, 2))\nplot(person2, main = \"Original Person 2\")\nplot(dilated_person2, main = \"Dilated Person 2\")\n\npar(mfrow = c(1, 2))\nplot(person1, main = \"Original Person 1\")\nplot(opened_person1, main = \"Opened Person 1\")\n\npar(mfrow = c(1, 2))\nplot(person2, main = \"Original Person 2\")\nplot(opened_person2, main = \"Opened Person 2\")\n\npar(mfrow = c(1, 2))\nplot(person1, main = \"Original Person 1\")\nplot(closed_person1, main = \"Closed Person 1\")\n\npar(mfrow = c(1, 2))\nplot(person2, main = \"Original Person 2\")\nplot(closed_person2, main = \"Closed Person 2\")\n```\n\n## **Conclusion**\n\nThis project demonstrates a comprehensive application of image processing techniques using R and the imager package. By analyzing the results, we can gain insights into how these techniques transform and enhance images.\n\n# \u003cdiv align=\"center\"\u003eEnjoy 👍\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazlinrusnan%2Fimage_analysis_using_r_and_imager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazlinrusnan%2Fimage_analysis_using_r_and_imager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazlinrusnan%2Fimage_analysis_using_r_and_imager/lists"}