{"id":680,"date":"2014-11-05T11:20:13","date_gmt":"2014-11-05T18:20:13","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=680"},"modified":"2014-11-05T11:20:13","modified_gmt":"2014-11-05T18:20:13","slug":"r-image-analysis-using-ebimage","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/11\/05\/r-image-analysis-using-ebimage\/","title":{"rendered":"R: Image Analysis using EBImage"},"content":{"rendered":"<div dir=\"ltr\">\n<div dir=\"ltr\">\n<div dir=\"ltr\">Currently, I am taking <i>Statistics for Image Analysis<\/i> on my masteral, and have been exploring this topic in R. One package that has the capability in this field is the <a href=\"http:\/\/www.bioconductor.org\/packages\/release\/bioc\/html\/EBImage.html\" target=\"_blank\" rel=\"noopener\">EBImage<\/a> from <a href=\"http:\/\/www.bioconductor.org\/\" target=\"_blank\" rel=\"noopener\">Bioconductor<\/a>, which will be showcased in this post.<\/p>\n<h3>Installation<\/h3>\n<div id=\"gist14215373\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim3-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim3-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim3-r-L3\" class=\"line-number\">3<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim3-r-LC1\" class=\"line\"><span class=\"kn\">source<\/span><span class=\"p\">(<\/span><span class=\"s\">&#8220;http:\/\/bioconductor.org\/biocLite.R&#8221;<\/span><span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim3-r-LC2\" class=\"line\">biocLite<span class=\"p\">()<\/span><\/div>\n<div id=\"file-ebim3-r-LC3\" class=\"line\">biocLite<span class=\"p\">(<\/span><span class=\"s\">&#8220;EBImage&#8221;<\/span><span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/83573359af6c57dcea4f\/raw\/EBIm3.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/83573359af6c57dcea4f#file-ebim3-r\">EBIm3.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<p>For those using Ubuntu, you may likely to encounter this error:<\/p>\n<div id=\"gist14167772\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-imageerr-r-L1\" class=\"line-number\">1<\/span><span id=\"file-imageerr-r-L2\" class=\"line-number\">2<\/span><span id=\"file-imageerr-r-L3\" class=\"line-number\">3<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-imageerr-r-LC1\" class=\"line\">In file included from common.c<span class=\"o\">:<\/span><span class=\"m\">1<\/span><span class=\"o\">:<\/span><span class=\"m\">0<\/span><span class=\"o\">:<\/span><\/div>\n<div id=\"file-imageerr-r-LC2\" class=\"line\">common.h<span class=\"o\">:<\/span><span class=\"m\">5<\/span><span class=\"o\">:<\/span><span class=\"m\">18<\/span><span class=\"o\">:<\/span> fatal error<span class=\"o\">:<\/span> tiff.h<span class=\"o\">:<\/span> No such file or directory<\/div>\n<div id=\"file-imageerr-r-LC3\" class=\"line\"><span class=\"c1\">#include &lt;tiff.h&gt;<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/3bec32e1ad17515d7b3a\/raw\/imageErr.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/3bec32e1ad17515d7b3a#file-imageerr-r\">imageErr.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<p>It has something to do with the <code>tiff.h<\/code> <a href=\"http:\/\/en.wikipedia.org\/wiki\/Include_directive\" target=\"_blank\" rel=\"noopener\">C header file<\/a>, but it&#8217;s not that serious since <a href=\"http:\/\/mytechscribblings.wordpress.com\/\" target=\"_blank\" rel=\"noopener\">mytechscribblings<\/a> has an effective <a href=\"http:\/\/mytechscribblings.wordpress.com\/2013\/06\/28\/installing-ebimage-package-for-r-using-rstudio-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">solution<\/a> for this, do check that out.<\/p>\n<h3>Importing Data<\/h3>\n<p>To import a raw image, consider the following codes:<br \/>\n<a name=\"more\"><\/a><\/p>\n<div id=\"gist14214603\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim1-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim1-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim1-r-L3\" class=\"line-number\">3<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim1-r-LC1\" class=\"line\"><span class=\"c1\"># Reading Image<\/span><\/div>\n<div id=\"file-ebim1-r-LC2\" class=\"line\">Image <span class=\"o\">&lt;-<\/span> readImage<span class=\"p\">(<\/span><span class=\"s\">&#8216;~\/Documents\/R Files\/Image Analysis\/tinago.JPG&#8217;<\/span><span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim1-r-LC3\" class=\"line\">display<span class=\"p\">(<\/span>Image<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/40778c752b73d5de4186\/raw\/EBIm1.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/40778c752b73d5de4186#file-ebim1-r\">EBIm1.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><a href=\"http:\/\/i0.wp.com\/3.bp.blogspot.com\/-aU5Ekm0dy3w\/VAHQnqK4y9I\/AAAAAAAABzo\/HJsl0LGi7kk\/s1600\/tinago.JPG\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i0.wp.com\/3.bp.blogspot.com\/-aU5Ekm0dy3w\/VAHQnqK4y9I\/AAAAAAAABzo\/HJsl0LGi7kk\/s1600\/tinago.JPG?resize=400%2C300\" alt=\"\" width=\"400\" height=\"300\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Yes, this is the photo that we are going to use for our analysis. Needless to say, that&#8217;s me and my friends. In the proceeding section we will do image manipulation and other processing.<\/p>\n<h3>Image Properties<\/h3>\n<p>So what do we get from our raw image? To answer that, simply run<code>print(Image)<\/code>. This will return the properties of the image, including the array of pixel values. With these information, we apply mathematical and statistical operations to do enhancement on the image.<\/p>\n<div id=\"gist14226855\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim4-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim4-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim4-r-L3\" class=\"line-number\">3<\/span><span id=\"file-ebim4-r-L4\" class=\"line-number\">4<\/span><span id=\"file-ebim4-r-L5\" class=\"line-number\">5<\/span><span id=\"file-ebim4-r-L6\" class=\"line-number\">6<\/span><span id=\"file-ebim4-r-L7\" class=\"line-number\">7<\/span><span id=\"file-ebim4-r-L8\" class=\"line-number\">8<\/span><span id=\"file-ebim4-r-L9\" class=\"line-number\">9<\/span><span id=\"file-ebim4-r-L10\" class=\"line-number\">10<\/span><span id=\"file-ebim4-r-L11\" class=\"line-number\">11<\/span><span id=\"file-ebim4-r-L12\" class=\"line-number\">12<\/span><span id=\"file-ebim4-r-L13\" class=\"line-number\">13<\/span><span id=\"file-ebim4-r-L14\" class=\"line-number\">14<\/span><span id=\"file-ebim4-r-L15\" class=\"line-number\">15<\/span><span id=\"file-ebim4-r-L16\" class=\"line-number\">16<\/span><span id=\"file-ebim4-r-L17\" class=\"line-number\">17<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim4-r-LC1\" class=\"line\"><span class=\"kp\">print<\/span><span class=\"p\">(<\/span>Image<span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim4-r-LC2\" class=\"line\"><\/div>\n<div id=\"file-ebim4-r-LC3\" class=\"line\"><span class=\"c1\">#OUTPUT<\/span><\/div>\n<div id=\"file-ebim4-r-LC4\" class=\"line\">Image<\/div>\n<div id=\"file-ebim4-r-LC5\" class=\"line\">colormode<span class=\"o\">:<\/span> Color<\/div>\n<div id=\"file-ebim4-r-LC6\" class=\"line\"><span class=\"kp\">storage.mode<\/span><span class=\"o\">:<\/span> <span class=\"kt\">double<\/span><\/div>\n<div id=\"file-ebim4-r-LC7\" class=\"line\"><span class=\"kp\">dim<\/span><span class=\"o\">:<\/span> <span class=\"m\">1984<\/span> <span class=\"m\">1488<\/span> <span class=\"m\">3<\/span><\/div>\n<div id=\"file-ebim4-r-LC8\" class=\"line\">nb.total.frames<span class=\"o\">:<\/span> <span class=\"m\">3<\/span><\/div>\n<div id=\"file-ebim4-r-LC9\" class=\"line\">nb.render.frames<span class=\"o\">:<\/span> <span class=\"m\">1<\/span><\/div>\n<div id=\"file-ebim4-r-LC10\" class=\"line\"><\/div>\n<div id=\"file-ebim4-r-LC11\" class=\"line\">imageData<span class=\"p\">(<\/span>object<span class=\"p\">)[<\/span><span class=\"m\">1<\/span><span class=\"o\">:<\/span><span class=\"m\">5<\/span><span class=\"p\">,<\/span><span class=\"m\">1<\/span><span class=\"o\">:<\/span><span class=\"m\">6<\/span><span class=\"p\">,<\/span><span class=\"m\">1<\/span><span class=\"p\">]<\/span><span class=\"o\">:<\/span><\/div>\n<div id=\"file-ebim4-r-LC12\" class=\"line\"><span class=\"p\">[,<\/span><span class=\"m\">1<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">2<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">3<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">4<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">5<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">6<\/span><span class=\"p\">]<\/span><\/div>\n<div id=\"file-ebim4-r-LC13\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">1<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.3647059<\/span> <span class=\"m\">0.3843137<\/span> <span class=\"m\">0.3803922<\/span> <span class=\"m\">0.3490196<\/span> <span class=\"m\">0.3215686<\/span> <span class=\"m\">0.3058824<\/span><\/div>\n<div id=\"file-ebim4-r-LC14\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">2<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4196078<\/span> <span class=\"m\">0.4000000<\/span> <span class=\"m\">0.3921569<\/span> <span class=\"m\">0.4039216<\/span> <span class=\"m\">0.3843137<\/span> <span class=\"m\">0.3254902<\/span><\/div>\n<div id=\"file-ebim4-r-LC15\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">3<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4784314<\/span> <span class=\"m\">0.4705882<\/span> <span class=\"m\">0.4705882<\/span> <span class=\"m\">0.4666667<\/span> <span class=\"m\">0.4117647<\/span> <span class=\"m\">0.3411765<\/span><\/div>\n<div id=\"file-ebim4-r-LC16\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">4<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4901961<\/span> <span class=\"m\">0.5647059<\/span> <span class=\"m\">0.5960784<\/span> <span class=\"m\">0.5411765<\/span> <span class=\"m\">0.4392157<\/span> <span class=\"m\">0.3843137<\/span><\/div>\n<div id=\"file-ebim4-r-LC17\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">5<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4509804<\/span> <span class=\"m\">0.5686275<\/span> <span class=\"m\">0.6549020<\/span> <span class=\"m\">0.6392157<\/span> <span class=\"m\">0.5607843<\/span> <span class=\"m\">0.4901961<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/abd3f84e2eb19fea58f9\/raw\/EBIm4.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/abd3f84e2eb19fea58f9#file-ebim4-r\">EBIm4.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<p>There are two sections (Summary and array of the pixels) in the above output, with the following entries for the first section:<\/p>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>CODE<\/th>\n<th>VALUE<\/th>\n<th>DESCRIPTION<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"3\">\n<div id=\"paging\"><i>Table 1: Information from 1st section of <code>print(Image)<\/code>.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td><code>colormode<\/code><\/td>\n<td>Color<\/td>\n<td>The type (Color\/Grayscale) of the color of the image.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td><code>storage.mode<\/code><\/td>\n<td>double<\/td>\n<td>Type of values in the array.<\/td>\n<\/tr>\n<tr>\n<td><code>dim<\/code><\/td>\n<td>1984 1488 3<\/td>\n<td>Dimension of the array, (x, y, z).<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td><code>nb.total.frames:<\/code><\/td>\n<td>3<\/td>\n<td>Number of channels in each pixel, z entry in <code>dim<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>nb.render.frames<\/code><\/td>\n<td>1<\/td>\n<td>Number of channels rendered.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The second section is the obtained values from mapping pixels in the image to the real line between 0 and 1 (inclusive). Both extremes of this interval [0, 1], are black and white colors, respectively. Hence, pixels with values closer to any of these end points are expected to be darker or lighter, respectively. And because pixels are contained in a large array, then we can do all matrix manipulations available in R for processing.<\/p>\n<h3>Adjusting Brightness<\/h3>\n<p>It is better to start with the basic first, one of which is the brightness. As discussed above, brightness can be manipulated using <code>+<\/code> or <code>-<\/code>:<\/p>\n<div id=\"gist14214810\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim2-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim2-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim2-r-L3\" class=\"line-number\">3<\/span><span id=\"file-ebim2-r-L4\" class=\"line-number\">4<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim2-r-LC1\" class=\"line\"><span class=\"c1\"># Brightness<\/span><\/div>\n<div id=\"file-ebim2-r-LC2\" class=\"line\">Image1 <span class=\"o\">&lt;-<\/span> Image <span class=\"o\">+<\/span> <span class=\"m\">0.2<\/span><\/div>\n<div id=\"file-ebim2-r-LC3\" class=\"line\">Image2 <span class=\"o\">&lt;-<\/span> Image <span class=\"o\">&#8211;<\/span> <span class=\"m\">0.2<\/span><\/div>\n<div id=\"file-ebim2-r-LC4\" class=\"line\">display<span class=\"p\">(<\/span>Image1<span class=\"p\">);<\/span> display<span class=\"p\">(<\/span>Image2<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/9994581ad659b5fdb124\/raw\/EBIm2.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/9994581ad659b5fdb124#file-ebim2-r\">EBIm2.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>LIGHTER<\/th>\n<th>DARKER<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"3\">\n<div id=\"paging\"><i>Table 2: Adjusting Brightness.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i2.wp.com\/2.bp.blogspot.com\/-JsJ7dJpYa2s\/VAMBpD4dGiI\/AAAAAAAAB0U\/bVrNeRZ8JXI\/s200\/Image3.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image1)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/1.bp.blogspot.com\/-UUeVdzjEYHQ\/VAMB12MtqnI\/AAAAAAAAB0c\/tTJIfzOLGgI\/s200\/Image2.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image2)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3>Adjusting Contrast<\/h3>\n<p>Contrast can be manipulated using multiplication operator(<code>*<\/code>):<\/p>\n<div id=\"gist14229098\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim5-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim5-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim5-r-L3\" class=\"line-number\">3<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim5-r-LC1\" class=\"line\">Image3 <span class=\"o\">&lt;-<\/span> Image <span class=\"o\">*<\/span> <span class=\"m\">0.5<\/span><\/div>\n<div id=\"file-ebim5-r-LC2\" class=\"line\">Image4 <span class=\"o\">&lt;-<\/span> Image <span class=\"o\">*<\/span> <span class=\"m\">2<\/span><\/div>\n<div id=\"file-ebim5-r-LC3\" class=\"line\">display<span class=\"p\">(<\/span>Image3<span class=\"p\">);<\/span> display<span class=\"p\">(<\/span>Image4<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/5ece4021aeef8c08d38d\/raw\/EBIm5.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/5ece4021aeef8c08d38d#file-ebim5-r\">EBIm5.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>LOW<\/th>\n<th>HIGH<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"3\">\n<div id=\"paging\"><i>Table 3: Adjusting Contrast.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/2.bp.blogspot.com\/-i1FyKHWzVOM\/VAMI6-a2gWI\/AAAAAAAAB0s\/VlpkNUPwPJE\/s200\/Image4.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image3)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i0.wp.com\/2.bp.blogspot.com\/-Qnmx9fToGaw\/VAMJGEJ-p5I\/AAAAAAAAB00\/Xv1gbcqJPAs\/s200\/Image5.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image4)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3>Gamma Correction<\/h3>\n<p>Gamma correction is the name of a nonlinear operation used to code and decode luminance or tristimulus values in video or still image systems, defined by the following power-law expression: begin{equation}nonumber V_{mathrm{out}} = AV_{mathrm{in}}^{gamma} end{equation} where $A$ is a constant and the input and output values are non-negative real values; in the common case of $A = 1$, inputs and outputs are typically in the range 0-1. A gamma value $gamma&lt; 1$ is sometimes called an <b>encoding gamma<\/b> (Wikipedia, Ref. 1).<\/p>\n<div id=\"gist14229464\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim6-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim6-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim6-r-L3\" class=\"line-number\">3<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim6-r-LC1\" class=\"line\">Image5 <span class=\"o\">&lt;-<\/span> Image <span class=\"o\">^<\/span> <span class=\"m\">2<\/span><\/div>\n<div id=\"file-ebim6-r-LC2\" class=\"line\">Image6 <span class=\"o\">&lt;-<\/span> Image <span class=\"o\">^<\/span> <span class=\"m\">0.7<\/span><\/div>\n<div id=\"file-ebim6-r-LC3\" class=\"line\">display<span class=\"p\">(<\/span>Image5<span class=\"p\">);<\/span> display<span class=\"p\">(<\/span>Image6<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/24632941aba052c44641\/raw\/EBIm6.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/24632941aba052c44641#file-ebim6-r\">EBIm6.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>$GAMMA = 2$<\/th>\n<th>$GAMMA = 0.7$<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"3\">\n<div id=\"paging\"><i>Table 4: Adjusting Gamma Correction.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/1.bp.blogspot.com\/-Rxqi8jvOOug\/VAMQmXXkxZI\/AAAAAAAAB1I\/SStU8diQO4U\/s200\/Image6.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image5)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i2.wp.com\/4.bp.blogspot.com\/-xjtN-snXoZA\/VAMQlW1JdjI\/AAAAAAAAB1E\/5GQY8yG0D9c\/s200\/Image7.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(Image6)<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>Cropping<\/h3>\n<p>Slicing array of pixels, simply mean cropping the image.<\/p>\n<div id=\"gist14229989\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim7-r-L1\" class=\"line-number\">1<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim7-r-LC1\" class=\"line\">display<span class=\"p\">(<\/span>Image<span class=\"p\">[<\/span><span class=\"m\">289<\/span><span class=\"o\">:<\/span><span class=\"m\">1547<\/span><span class=\"p\">,<\/span> <span class=\"m\">669<\/span><span class=\"o\">:<\/span><span class=\"m\">1406<\/span><span class=\"p\">,])<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/8a5b5cf36dc74be36574\/raw\/EBIm7.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/8a5b5cf36dc74be36574#file-ebim7-r\">EBIm7.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/3.bp.blogspot.com\/-gBgEMu2lyl4\/VAMZUDsTO6I\/AAAAAAAAB1k\/aBr4ADJHo1k\/s1600\/Image8.png?resize=320%2C187\" alt=\"\" width=\"320\" height=\"187\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of the above code.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<h3>Spatial Transformation<\/h3>\n<p>Spatial manipulation like rotate (<code>rotate<\/code>), flip (<code>flip<\/code>), and translate (<code>translate<\/code>) are also available in the package. Check this out,<\/p>\n<div id=\"gist14230276\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim8-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim8-r-L2\" class=\"line-number\">2<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim8-r-LC1\" class=\"line\">Imagetr <span class=\"o\">&lt;-<\/span> translate<span class=\"p\">(<\/span>rotate<span class=\"p\">(<\/span>Image<span class=\"p\">,<\/span> <span class=\"m\">45<\/span><span class=\"p\">),<\/span> <span class=\"kt\">c<\/span><span class=\"p\">(<\/span><span class=\"m\">50<\/span><span class=\"p\">,<\/span> <span class=\"m\">0<\/span><span class=\"p\">))<\/span><\/div>\n<div id=\"file-ebim8-r-LC2\" class=\"line\">display<span class=\"p\">(<\/span>Imagetr<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/8fde183b0944c1044fb2\/raw\/EBIm8.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/8fde183b0944c1044fb2#file-ebim8-r\">EBIm8.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/3.bp.blogspot.com\/-r0Er7_ZoujQ\/VAMhT7RP_HI\/AAAAAAAAB10\/DmBjiZ6yFmc\/s1600\/Image9.png?resize=320%2C240\" alt=\"\" width=\"320\" height=\"240\" border=\"0\" \/><\/div>\n<h3>Color Management<\/h3>\n<p>Since the array of pixels has three axes in its dimension, for example in our case is 1984 x 1488 x 3. The third axis is the slot for the three channels: Red, Green and Blue, or RGB. Hence, transforming the <code>color.mode<\/code> from <code>Color<\/code> to<code>Grayscale<\/code>, implies disjoining the three channels from single rendered frame (three channels for each pixel) to three separate array of pixels for red, green, and blue frames.<\/p>\n<div id=\"gist14239965\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim9-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim9-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim9-r-L3\" class=\"line-number\">3<\/span><span id=\"file-ebim9-r-L4\" class=\"line-number\">4<\/span><span id=\"file-ebim9-r-L5\" class=\"line-number\">5<\/span><span id=\"file-ebim9-r-L6\" class=\"line-number\">6<\/span><span id=\"file-ebim9-r-L7\" class=\"line-number\">7<\/span><span id=\"file-ebim9-r-L8\" class=\"line-number\">8<\/span><span id=\"file-ebim9-r-L9\" class=\"line-number\">9<\/span><span id=\"file-ebim9-r-L10\" class=\"line-number\">10<\/span><span id=\"file-ebim9-r-L11\" class=\"line-number\">11<\/span><span id=\"file-ebim9-r-L12\" class=\"line-number\">12<\/span><span id=\"file-ebim9-r-L13\" class=\"line-number\">13<\/span><span id=\"file-ebim9-r-L14\" class=\"line-number\">14<\/span><span id=\"file-ebim9-r-L15\" class=\"line-number\">15<\/span><span id=\"file-ebim9-r-L16\" class=\"line-number\">16<\/span><span id=\"file-ebim9-r-L17\" class=\"line-number\">17<\/span><span id=\"file-ebim9-r-L18\" class=\"line-number\">18<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim9-r-LC1\" class=\"line\">colorMode<span class=\"p\">(<\/span>Image<span class=\"p\">)<\/span> <span class=\"o\">&lt;-<\/span> Grayscale<\/div>\n<div id=\"file-ebim9-r-LC2\" class=\"line\"><span class=\"kp\">print<\/span><span class=\"p\">(<\/span>Image<span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim9-r-LC3\" class=\"line\"><\/div>\n<div id=\"file-ebim9-r-LC4\" class=\"line\"><span class=\"c1\">#OUTPUT<\/span><\/div>\n<div id=\"file-ebim9-r-LC5\" class=\"line\">Image<\/div>\n<div id=\"file-ebim9-r-LC6\" class=\"line\">colormode<span class=\"o\">:<\/span> Grayscale<\/div>\n<div id=\"file-ebim9-r-LC7\" class=\"line\"><span class=\"kp\">storage.mode<\/span><span class=\"o\">:<\/span> <span class=\"kt\">double<\/span><\/div>\n<div id=\"file-ebim9-r-LC8\" class=\"line\"><span class=\"kp\">dim<\/span><span class=\"o\">:<\/span> <span class=\"m\">1984<\/span> <span class=\"m\">1488<\/span> <span class=\"m\">3<\/span><\/div>\n<div id=\"file-ebim9-r-LC9\" class=\"line\">nb.total.frames<span class=\"o\">:<\/span> <span class=\"m\">3<\/span><\/div>\n<div id=\"file-ebim9-r-LC10\" class=\"line\">nb.render.frames<span class=\"o\">:<\/span> <span class=\"m\">3<\/span><\/div>\n<div id=\"file-ebim9-r-LC11\" class=\"line\"><\/div>\n<div id=\"file-ebim9-r-LC12\" class=\"line\">imageData<span class=\"p\">(<\/span>object<span class=\"p\">)[<\/span><span class=\"m\">1<\/span><span class=\"o\">:<\/span><span class=\"m\">5<\/span><span class=\"p\">,<\/span><span class=\"m\">1<\/span><span class=\"o\">:<\/span><span class=\"m\">6<\/span><span class=\"p\">,<\/span><span class=\"m\">1<\/span><span class=\"p\">]<\/span><span class=\"o\">:<\/span><\/div>\n<div id=\"file-ebim9-r-LC13\" class=\"line\"><span class=\"p\">[,<\/span><span class=\"m\">1<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">2<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">3<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">4<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">5<\/span><span class=\"p\">]<\/span> <span class=\"p\">[,<\/span><span class=\"m\">6<\/span><span class=\"p\">]<\/span><\/div>\n<div id=\"file-ebim9-r-LC14\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">1<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.3647059<\/span> <span class=\"m\">0.3843137<\/span> <span class=\"m\">0.3803922<\/span> <span class=\"m\">0.3490196<\/span> <span class=\"m\">0.3215686<\/span> <span class=\"m\">0.3058824<\/span><\/div>\n<div id=\"file-ebim9-r-LC15\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">2<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4196078<\/span> <span class=\"m\">0.4000000<\/span> <span class=\"m\">0.3921569<\/span> <span class=\"m\">0.4039216<\/span> <span class=\"m\">0.3843137<\/span> <span class=\"m\">0.3254902<\/span><\/div>\n<div id=\"file-ebim9-r-LC16\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">3<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4784314<\/span> <span class=\"m\">0.4705882<\/span> <span class=\"m\">0.4705882<\/span> <span class=\"m\">0.4666667<\/span> <span class=\"m\">0.4117647<\/span> <span class=\"m\">0.3411765<\/span><\/div>\n<div id=\"file-ebim9-r-LC17\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">4<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4901961<\/span> <span class=\"m\">0.5647059<\/span> <span class=\"m\">0.5960784<\/span> <span class=\"m\">0.5411765<\/span> <span class=\"m\">0.4392157<\/span> <span class=\"m\">0.3843137<\/span><\/div>\n<div id=\"file-ebim9-r-LC18\" class=\"line\"><span class=\"p\">[<\/span><span class=\"m\">5<\/span><span class=\"p\">,]<\/span> <span class=\"m\">0.4509804<\/span> <span class=\"m\">0.5686275<\/span> <span class=\"m\">0.6549020<\/span> <span class=\"m\">0.6392157<\/span> <span class=\"m\">0.5607843<\/span> <span class=\"m\">0.4901961<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/7c2348ec3131ae6a173f\/raw\/EBIm9.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/7c2348ec3131ae6a173f#file-ebim9-r\">EBIm9.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>ORIGINAL<\/th>\n<th>RED CHANNEL<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"3\">\n<div id=\"paging\"><i>Table 5: Color Mode Transformation.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i0.wp.com\/3.bp.blogspot.com\/-LpJwYSJnnlY\/VAPdM9pTZqI\/AAAAAAAAB2M\/GAAkfgyh-7s\/s200\/Image1.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/div>\n<\/td>\n<td>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i0.wp.com\/4.bp.blogspot.com\/-bEumwca398k\/VAPdUTsdwqI\/AAAAAAAAB2c\/VBWZAZONYsg\/s200\/Image10.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<thead>\n<tr>\n<th>GREEN CHANNEL<\/th>\n<th>BLUE CHANNEL<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i2.wp.com\/2.bp.blogspot.com\/-4XZVeVpSX6Q\/VAPdPQe74BI\/AAAAAAAAB2Q\/cAbSsxX_MBA\/s200\/Image10-g.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/div>\n<\/td>\n<td>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/1.bp.blogspot.com\/-FoAUdUx_FQw\/VAPdAG7KwqI\/AAAAAAAAB2E\/jCoAAG5IAuk\/s200\/Image10-b.png?w=456\" alt=\"\" width=\"200\" height=\"150\" border=\"0\" \/><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>To revert the color mode, simply run<\/p>\n<div id=\"gist14297243\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim12-r-L1\" class=\"line-number\">1<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim12-r-LC1\" class=\"line\">colorMode<span class=\"p\">(<\/span>Image<span class=\"p\">)<\/span> <span class=\"o\">&lt;-<\/span> Color<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/2e92358020609764e8a6\/raw\/EBIm12.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/2e92358020609764e8a6#file-ebim12-r\">EBIm12.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<h3>Filtering<\/h3>\n<p>In this section, we will do smoothing\/blurring using low-pass filter, and edge-detection using high-pass filter. In addition, we will also investigate median filter to remove noise.<\/p>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>LOW-PASS (BLUR)<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td>\n<div id=\"paging\"><i>Table 6: Image Filtering.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i0.wp.com\/4.bp.blogspot.com\/-4OrEcnvm3OU\/VAcZC-_-ZrI\/AAAAAAAAB3E\/rIFQcOxqNPo\/s320\/Image11.png?w=456\" alt=\"\" width=\"320\" height=\"240\" border=\"0\" \/><\/div>\n<div>\n<div id=\"gist14295269\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim10-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim10-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim10-r-L3\" class=\"line-number\">3<\/span><span id=\"file-ebim10-r-L4\" class=\"line-number\">4<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim10-r-LC1\" class=\"line\">fLow <span class=\"o\">&lt;-<\/span> makeBrush<span class=\"p\">(<\/span><span class=\"m\">21<\/span><span class=\"p\">,<\/span> shape<span class=\"o\">=<\/span> <span class=\"s\">&#8216;disc&#8217;<\/span><span class=\"p\">,<\/span> step<span class=\"o\">=<\/span><span class=\"kc\">FALSE<\/span><span class=\"p\">)<\/span><span class=\"o\">^<\/span><span class=\"m\">2<\/span><\/div>\n<div id=\"file-ebim10-r-LC2\" class=\"line\">fLow <span class=\"o\">&lt;-<\/span> fLow<span class=\"o\">\/<\/span><span class=\"kp\">sum<\/span><span class=\"p\">(<\/span>fLow<span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim10-r-LC3\" class=\"line\">Image.fLow <span class=\"o\">&lt;-<\/span> filter2<span class=\"p\">(<\/span>Image<span class=\"p\">,<\/span> fLow<span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim10-r-LC4\" class=\"line\">display<span class=\"p\">(<\/span>Image.fLow<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/8c0f1a2ed48383277f8f\/raw\/EBIm10.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/8c0f1a2ed48383277f8f#file-ebim10-r\">EBIm10.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<thead>\n<tr>\n<th>HIGH PASS<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i0.wp.com\/3.bp.blogspot.com\/-UstcJqiIEGw\/VAcfWdJmTfI\/AAAAAAAAB3Q\/Dae_SpFAo9Q\/s320\/Image12.png?w=456\" alt=\"\" width=\"320\" height=\"240\" border=\"0\" \/><\/div>\n<div>\n<div id=\"gist14295343\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim11-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim11-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim11-r-L3\" class=\"line-number\">3<\/span><span id=\"file-ebim11-r-L4\" class=\"line-number\">4<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim11-r-LC1\" class=\"line\">fHigh <span class=\"o\">&lt;-<\/span> <span class=\"kt\">matrix<\/span><span class=\"p\">(<\/span><span class=\"m\">1<\/span><span class=\"p\">,<\/span> nc <span class=\"o\">=<\/span> <span class=\"m\">3<\/span><span class=\"p\">,<\/span> nr <span class=\"o\">=<\/span> <span class=\"m\">3<\/span><span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim11-r-LC2\" class=\"line\">fHigh<span class=\"p\">[<\/span><span class=\"m\">2<\/span><span class=\"p\">,<\/span> <span class=\"m\">2<\/span><span class=\"p\">]<\/span> <span class=\"o\">&lt;-<\/span> <span class=\"m\">-8<\/span><\/div>\n<div id=\"file-ebim11-r-LC3\" class=\"line\">Image.fHigh <span class=\"o\">&lt;-<\/span> filter2<span class=\"p\">(<\/span>Image<span class=\"p\">,<\/span> fHigh<span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim11-r-LC4\" class=\"line\">display<span class=\"p\">(<\/span>Image.fHigh<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/1ef92750b21735e39366\/raw\/EBIm11.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/1ef92750b21735e39366#file-ebim11-r\">EBIm11.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"datagrid\">\n<table>\n<thead>\n<tr>\n<th>ORIGINAL<\/th>\n<th>FILTERED<\/th>\n<\/tr>\n<\/thead>\n<tfoot>\n<tr>\n<td colspan=\"3\">\n<div id=\"paging\"><i>Table 7: Median Filter.<\/i><\/div>\n<\/td>\n<\/tr>\n<\/tfoot>\n<tbody>\n<tr>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i1.wp.com\/4.bp.blogspot.com\/-dU4IZFWF7v4\/VAh81coGXoI\/AAAAAAAAB4U\/0xrOTbWGW1Y\/s1600\/peppersalt.jpg?resize=200%2C200\" alt=\"\" width=\"200\" height=\"200\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">From Google, Link <a href=\"http:\/\/my.fit.edu\/~vkepuska\/ece3552\/esp_book\/adsp\/chap10\/image_files\/noisy_image\/peppersalt.bmp\" target=\"_blank\" rel=\"noopener\">Here<\/a>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<td>\n<table class=\"tr-caption-container\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i2.wp.com\/1.bp.blogspot.com\/-42jV21UCWxQ\/VAh9rfngXoI\/AAAAAAAAB4c\/uNanHSHrc9U\/s1600\/psfiltered.png?resize=200%2C200\" alt=\"\" width=\"200\" height=\"200\" border=\"0\" \/><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\">Output of <code>display(medFltr)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"separator\"><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<div id=\"gist14320177\" class=\"gist\">\n<div class=\"gist-file\">\n<div class=\"gist-data gist-syntax\">\n<div class=\"file-data\">\n<table class=\"lines highlight\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"line-numbers\"><span id=\"file-ebim13-r-L1\" class=\"line-number\">1<\/span><span id=\"file-ebim13-r-L2\" class=\"line-number\">2<\/span><span id=\"file-ebim13-r-L3\" class=\"line-number\">3<\/span><\/td>\n<td class=\"line-data\">\n<div id=\"file-ebim13-r-LC1\" class=\"line\">Image <span class=\"o\">&lt;-<\/span> readImage<span class=\"p\">(<\/span><span class=\"s\">&#8220;~\/Documents\/R Files\/Image Analysis\/peppersalt.jpg&#8221;<\/span><span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim13-r-LC2\" class=\"line\">medFltr <span class=\"o\">&lt;-<\/span> medianFilter<span class=\"p\">(<\/span>Image<span class=\"p\">,<\/span> <span class=\"m\">1.1<\/span><span class=\"p\">)<\/span><\/div>\n<div id=\"file-ebim13-r-LC3\" class=\"line\">display<span class=\"p\">(<\/span>medFltr<span class=\"p\">)<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"gist-meta\"><a href=\"https:\/\/gist.github.com\/alstat\/d0630e5c6420fc6cad9a\/raw\/EBIm13.R\">view raw<\/a><a href=\"https:\/\/gist.github.com\/alstat\/d0630e5c6420fc6cad9a#file-ebim13-r\">EBIm13.R<\/a> hosted with \u2764 by <a href=\"https:\/\/github.com\/\">GitHub<\/a><\/div>\n<\/div>\n<\/div>\n<p>For comparison, I run median filter on first-neighborhood in Mathematica, and I got this<\/p>\n<div class=\"separator\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/i2.wp.com\/4.bp.blogspot.com\/-vQnyLYJZNQc\/VAiC-oWPatI\/AAAAAAAAB4s\/9l63YV6ElOY\/s1600\/M10MedFilter.png?w=456\" alt=\"\" width=\"256\" height=\"256\" border=\"0\" \/><\/div>\n<p>Clearly, Mathematica has better enhancement than R for this particular filter. But R has a good foundation already, as we witness with EBImage. There are still lots of interesting functions in the said package, that is worth exploring, I suggest you check that out.<\/p>\n<p>For the meantime, we will stop here, but hoping we can play more on this topic in the succeeding post.<\/p>\n<h3>References<\/h3>\n<ol>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Gamma_correction\" target=\"_blank\" rel=\"noopener\">Gamma Correction<\/a>. <i><a href=\"http:\/\/en.wikipedia.org\/wiki\/Main_Page\" target=\"_blank\" rel=\"noopener\">Wikipedia<\/a><\/i>. Retrieved August 31, 2014.<\/li>\n<li>Gregoire Pau, Oleg Sklyar, Wolfgang Huber (2014). <i><a href=\"http:\/\/www.google.com\/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0CB8QFjAA&amp;url=http%3A%2F%2Fwww.bioconductor.org%2Fpackages%2Frelease%2Fbioc%2Fvignettes%2FEBImage%2Finst%2Fdoc%2FEBImage-introduction.pdf&amp;ei=GdgDVO2jC4HViwLegYG4Dg&amp;usg=AFQjCNEsZZ5NXZGjo_IkuvYR0g759ik6hA&amp;sig2=grKJQ70YXN-vdqZDb0RBVQ&amp;bvm=bv.74115972,d.cGE\" target=\"_blank\" rel=\"noopener\">Introduction to EBImage, an image processing and analysis toolkit for R<\/a><\/i>.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Currently, I am taking Statistics for Image Analysis on my masteral, and have been exploring this topic in R. One package that has the capability&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-680","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/680\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}