Miyerkules, Nobyembre 29, 2017

Darkness to Light: Enhancement by Histogram Manipulation

This activity is pretty simple, you have an image with unequal bright and dark tones, and then you try to equalize it to make it look better. I generally enjoyed doing this activity especially since it brings satisfaction from the revelation of what a poorly contrasted image was hiding. 

In the intro part of the manual, Ma'am Jing said that we should not trust our eyes. I say, yes it is true. Colors of images depend not just on its hue but mostly on the camera settings (trinity of colors, remember? 187?) Good for us, humans, our eyes have rods that adjusts contrasts on the environment that we are looking at so we can have a good perception of the reality. Due to the vast improvement of science, most the technology of today can mimic or surpass the way our eyes work. Even some of our hand held phone cameras can already capture information that our eyes cannot see. 

There will always be cases however, that some important data, such as crime scene evidence, extinct animal sightings, underwater explorations, and many others, may sometimes be poorly contrasted due to the intense environment settings (dark room, too bright background, camouflaging objects, moving objects, etc) . With the proper tools, the stored information in those images can be extracted to maximize the value of those seemingly lost data, and reveal things our eyes have never seen before. 

For the activity, the PDF of the image was obtained. Naturally, for a good image, the PDF should somehow look like a horizontal line, indicating equal distribution of all the possible intensities. A too dark image would have peaks at the left part of the PDF, which are the 0 or the dark pixels and the PDF may cluster at the left part. A too light image will have peaks or clusters at the right part, indicating 255 or the white pixels. Some image may have intense contrast such that it has peaks far apart from each other, which are too light and too dark. A poorly contrasted image however, has a PDF clustered at one side. A highly contrasted image has peaks at the opposite end of the graph showing too dark and too light pixels. To enhance the image, the desired PDF should be a horizontal line, spread out along all intensities. This is the expected PDF of a well-contrasted image. The image enhancement by histogram manipulation basically is using a desired CDF (or the cumulative distribution function of the PDF) and back projecting the new grayscale values of the image referencing on the original CDF. So, to equalize the intensities, the desired CDF will be a line with a positive slope. 

I have to apply the histogram manipulation to a poorly contrasted image. It took me a hard time to search for an image in my phone since the images nowadays are of good quality and I've already deleted unnecessary photos. I stumbled upon this picture of Rey I've taken when IPL was going for lunch after a Gen Clean in the lab. The image has a bad contrast since the focus was set on the sky at the back ground, which made the foreground look very dark. You wouldn't know it was Rey in the picture at first, right? I even questioned the reason myself on why I still haven't deleted it since I can't comprehend anything from the original image. After swiping some other pictures taken a few moments after the photo was taken (one will be shown near the end of this blog post), then I realized what this photo was supposed to show. I still can't remember though, why I let this bad photo consume space on my phone. 

Anyway, going straight to the point, I used the original image as shown in figure 1(a) and tried to equalize the histogram of the intensities. The result as shown in figure 1(b) is pretty okay. However it became lighter and looks faded as confirmed by the low contrast shown by the histogram. Also, a big spike at some pixel lighter than the original peak in the histogram was created. Due to the limitation of the back projection done in the methodology, most of the domineering pixels, which are dark pixels, in the original image got transformed to a lighter pixel as shown by the new CDF in figure 1(d) where the values at the start of the line has 0 y-values. This result seems like the image did not get enhanced but was rendered far from the original image. However, a lot of details was revealed which are not observable in the original image.  

Figure 1. An enhanced image originally taken with a focus on the sky. (a) The original colored image. (b) The image enhanced by linearizing the intensities. (c) The distributions of the intensities for the original and enhanced image. (d) The CDF


Since the image in figure 1(a) was captured against the light, where the background is a very bright light source, linearizing the contrast of the image makes the image faded due to the limitation or the discreteness of the CDF felt during the backprojection. The rendering of the image was improved by using the fraction of the original intensities after linearizing the intensities of the image. The result shown in figure 2 (a) shows an improved image. The PDF of the histogram also shows that the peak shifted to the left which is nearer to the original peak in the histogram. Not much change in the number of revealed details was observed compared to the result using the linear CDF.  


Figure 2. (a) The image enhanced by linearizing the intensities and using a fraction of the original intensities to render a better image (b) The histogram of the intensities showing the peak nearer to the peak of the original image. (c) The CDF showing a slight distortion due to the original CDF of the image. 

Discovering the effect of other desired CDFs, I used the sigmoid, exponential and log functions. The sigmoid CDF resulted to an image showing more details than the original. The image however is more faded that the image obtained from the linear CDF. The small tree branches are not well defined with the sigmoid CDF compared to the linear CDF. The exponential CDF in figure 4 rendered a bad image as a lot of the fine details at the back ground were removed. Some details in the foreground however was revealed but the image is so faded. The result using the log CDF is okay since the rendered image is not faded and a lot of details were revealed.

Figure 3. (a) The image enhanced using a sigmoid CDF. (b) The histogram showing the dark colored pixels are removed and the peak shifted to a lighter pixel. (c) The CDF of a sigmoid. 



Figure 4. (a) The image enhanced using a CDF where x = ya  where a is a positive number. (b) The histogram showing increased height of the peaks near light pixels. (c) The CDF resulting from the discretization of the original CDF. 


Figure 5. (a) The image resulting from a desired CDF where x = ya where a is a fraction. (b) The histogram showing the peaks at the dark colored pixels shifted to the right compared to the original histogram. (c) The CDF of the image. 

So far, with the original image, the best enhancement was made using the linear CDF and the log CDF. Yes, it is true that a lot of details not seen in the original was revealed in the enhanced images. However, the enhanced images are only in its intensity. The RGB details of the images were already lost. I was challenged on thinking of a way to be able to render a colored version of the enhanced image. First, I thought of manipulating the CDF of the R, G, and B channels separately and then restacking the separate channels to show the original image. Figure 6 (a) shows the rendered image after separately linearizing the CDF of the channels, and figure 6 (b) shows the result after using a log CDF of the channels. The images rendered is not that good but is actually still better than the original image. A lot of details on the color of the objects in the image which was not very visible in the original image was now revealed such as the blue shirt worn by RM (the person at the left side of Rey), which looks black in the original image in figure 1 (a). In the resulting images, the R, G, and B ratios were not preserved, which explains the faded result since most of the colors became white due to the linearized intensity of the R, G, and B channels. Figure 6 (c) shows the resulting image while preserving the ratios among the color channels with reference white balancing. As can be seen, red noise is visible and the skin color is reddish. I also tried using the hsv channels of the images however I failed to reconstruct the ideal colors of the objects since the image became yellow-greenish all over. After doing a lot of trial and error with using the RGB or the hsv channels and using difference desired CDFs, I accounted the red noise to the lost data due to the poor contrast in the original image.  To compare the result to the expected real world colors, I showed figure 6 (d) which is the image I captured a few seconds after capturing figure 1 (a) but now with the smart phone camera adjusted to focus on the foreground. See how much details was lost by comparing figure 1 (a) and figure 6 (d). It is indeed vital to know how to focus on the important things to be able to show the essential details. Good thing, we have technology to extract the details we lost due to are mistakes. We are still learning anyway.

Figure 6. (a) Image rendered by linearizing the CDF of the R, G, and B channels. (b) The image rendered be separating the R, G, and B channels and using a log CDF for each. (c) Image rendered using a linear CDF for each R, G, and B channels and preserving the ratios among each color channels with reference white balancing. (d) A colored image taken a few moments after the image in figure 1 (a) was taken, but with the proper camera settings to show the details in the foreground.

For this activity, I give myself 10/10 since I was able to enhance the intensity of a poorly contrasted image using different CDFs. I had a lot of fun doing the activity but it took me a long time to figure out how to properly preserve the color after the histogram manipulation. For the image in figure 1 (a) the best image was shown in figure 6 (c) which is not that good. I tried using other images and the results are better.

For the image is shown in figure 7. The left panels shows the original image (figure 7 (a) and (d)), the middle panels shows the images with the contrast enhanced using a linear CDF (figure 7 (b) and (e)), and the right panels shows the images with the histogram of the RGB channels separately manipulated. Figure 7 (a) is an image of my brother with our dog, the image is a bit highly contrasted since it was taken against the light source, making the skin look dark and the window railings at the lower left part unseen. After the manipulation shown in figure 7 (c), the edges of the window railings were revealed and the skin became lighter. The edge of the roof at the background was also revealed. 
Figure 7 (d) is an image of the BS5 CSG boys during SPP. Due to the bad camera settings, a dark void can be seen near Justin’s hair and at the left side of Rey’s head. The general mood of the image is also cold and a bit gloomy. After the manipulation as shown in figure 7 (f), the edges at the stage (near Justin’s hair) were revealed. Details were also shown near Rey’s hair. Due to the manipulation, the surroundings became lighter giving the image a joyful atmosphere.

Figure 7. (a) and (d) The original colored images. (b) The enhanced image of (a) using a linear CDF. (c) The image in (a)  enhanced with the color information preserved. (e) The enhanced image of (d) by linearizing the CDF. (f) The image in (d) enhanced with the color information preserved. 

Reality is to be found in lightness and darkness - Pablo Picasso

Linggo, Setyembre 3, 2017

Edge of a Circle: Area Estimation in Images using Green's Theorem

Technological advancements of today has wide applications on a lot of aspects of our life. One of them is through area estimation using only image processing. This would be helpful is estimating land areas where it only requires an image and a conversion factor of the pixel size to actual length scales. One example would be area estimation of regions in the Mars taken by Curiosity. In this activity, we were tasked to use Green’s Theorem as a method of area estimation. I also used morphological operation by getting the sum of the pixels inside a known shape and compared it with the result of Green’s Theorem and the known area of the shape based on its radius or side. 

Green’s Theorem obtains the area A of the regions R using the contour of the edges of the area obtained in a clockwise direction.
 In discrete form,

For obtaining the contour of each shape, I used the edge function in Matlab with Canny as the method. I compared the result of the Green’s Theorem to the sum of the white pixels in the image and to the result of using the formula for the area of each shape. I obtained the center of the image from the mean of the x axis and mean of the y axis of the edged of the shape. Then, I used the function sort to sort the theta in increasing order. This function returns the old indices arranged now in the way it was sorted. The indices was used to rearrange the x and y coordinates.

 For the activity, I used a circle, square, triangle, and a parallelogram as test shapes. Varying the pixels sizes of the image, I used 10x10, 50x50, 100x100, and 500x500. 

In figure 1, increasing the pixel size increases the accuracy of the Green’s Theorem method. This is affected by the edge detection done since looking at the circle in the 50x50 px image, the circle is not completely round looking at the sides. At the extreme case, in figure 1 a) for the 10x10 px image, the image is now a square, which opens a lot of inaccuracy at the corners considering that the radius of the circle remained constant. The table below summarizes the percent difference of the area obtained using the Green’s Theorem, compared with the area obtained using an empirical formula (formula) and the area obtained from the sum of the white pixels (sum). Same thing was done for the square in figure 2, triangle in figure 3, and parallelogram in figure 4. 
Resolution of Circle (px)
Formula (%)
Sum (%)
10x10
9.9237
31.25
50x50
1.4975
1.2821
100x100
0.5524
0.8558
500x500
0.1269
0.1277

Figure 1. The circles used with varying pixel size. a) 10x10 px image. b) 50x50 px image. c) 100x100 px image. d) 500x500 px image. The radius of the circle used was 0.25 the length of the whole square image. 

The summary of the area estimation done using a sqaure is shown in the table below.
Resolution of Square (px)
Formula (%)
Sum (%)
10x10
31.25
31.25
50x50
1.7361
1.7361
100x100
0.66
0.66
500x500
0.1064
0.1064

Figure 2. The squares used with varying pixel size. a) 10x10 px image. b) 50x50 px image. c) 100x100 px image. d) 500x500 px image. The size of the square used was 0.5 of the length of the whole image.

The summary of the area estimation done using a triangle is shown in the table below.
Resolution of Triangle (px)
Formula (%)
Sum (%)
10x10
12.5
12.5
50x50
14.876
3.4722
100x100
7.2917
1.12
500x500
1.4723
0.1448

Figure 3. The triangles used with varying pixel size. a) 10x10 px image. b) 50x50 px image. c) 100x100 px image. d) 500x500 px image. The base and height of the triangle was 0.5 of the length of the image. 

The summary of the area estimation done using a parallelogram is shown in the table below.
Resolution of Parallelogram (px)
Formula (%)
Sum (%)
10x10
30.314
30.314
50x50
10.2941
1.3158
100x100
4.8423
0.5342
500x500
0.9264
0.0879


Figure 4. The parallelogram used with varying pixel size. a) 10x10 px image. b) 50x50 px image. c) 100x100 px image. d) 500x500 px image. 

Overall, the accuracy of the area estimation increases as the resolution increase for all the shapes. The least accurate for high resolutions in the triangle. which could be due to the angle of inclination of the sides. The formula also has a comparable difference in accuracy with the sum. This could be due to the rendering done in the images. 

I used the Green's theorem for estimating the area of the QMC circle. From google maps, the screen shot of the QMC circle in figure 5 has a lot of colors, which would give errors in the edge detection technique used. So, before running the image to the code, I created a mask using GIMP to show only the region of the QMC. The mask is depicted by the black pixels as shown in figure 6. Further processing shown in figure 7 converts the image to binary, with the region of interest shown in white pixels. 

Figure 5. The screenshot of the QMC circle. The conversion factor for the area was 8826 pixels per 10000 square meters. The area of the QMC circle is 0.27 square km based on Wikipedia. 

Figure 6. The screenshot of the QMC with a mask to highlight only the region of interest.

Figure 7. The screenshot of the QMC in binary, with the region of interest depicted in white pixels. 

Green’s Theorem gives an area of 0.2932 square km which deviates by 8.5926% from the result from Wikipedia. Comparing with the sum of the white pixels, the deviation of the method is 0.0587%. From these number, I say that the method is pretty good as long as the resolution is high enough to yield good results.

Overall, this activity is okay for me. I didn’t enjoy repeating the same method with different shapes. However, the part where I have to manipulate the screen shot of Google maps bothers me most since I feel like it required a lot of human intervention while I thought this method would be for automation of area estimation. I don’t like the part where I have to trace the perimeter of the desired object and color and recolor them into a binary image since I feel like there is an image processing method to do that. 

For the next part, I tried doing a different method by isolating a part of the image with a certain color instead of binarizing the image. The problem here is to find a pixels values which is at the middle of the range of values in the image. Compared to thresholding, the binarization should be done with a range of pixel values be assigned to white and the rest to be black. I tried searching on matlab examples, and I found about about k-means segmentation. This method segments the image based on its color using the function kmeans, which separates groups into clusters. In this case, the rgb image is converted into L*a*b* color space which identifies the colors into its luminosity layer L, chromaticity-layer a* or the red-green axis, and the chromaticity-layer b* or the location of the color along the blue-yellow axis (this was also our lesson in 187!!). For the k-means clustering, the object locations was obtained from the a*b* space and clusters using the Euclidean distance matrix.

I used a screenshot of the top view of Mayon Volcano. In Google maps, the considered range of the area of Mayon was depicted in a certain shade of green which could be located in figure 8. I tried to obtain the area of this region, first by isolating it using k-means clustering. The region was successfully separated from the other elements of the image. This results makes me super happy as the segmentation done by the program was so clean, I can even use one of the clusters indicating water ways if ever I want to. I feel energized to do more. The cluster which obtained the region of interest, ROI, which is the Mayon Volcano, was however not that good. It can be seen from figure 9 c) that there are small green regions outside of the ROI and cracks inside the ROI. I thought that repairing this region is okay since I acquired enough energy from the successful segmentation, to search even more. I’m also particularly grateful since while searching for this method, I learned about another method of segmentation, which is the watershed segmentation, that could probably be useful for my research. For more info, you may check on my research blog.

Figure 8. Screenshot of the top view of Mayon Volcano. The region of interest is the big circular region in a greenish hue. 

Figure 9. The image successfully segmented into different components using k-means clustering along the a*b* space. The region of interest in in the third cluster in c).

Separating and reparing the region of interest is harder than I thought since the shape is not a regular circle. I tried using the imfindcircles function but it can’t detect the irregular shape.  I also thought of using the function regionprops, but the cracks would still be detected as edges. This is when I thought of comparing the area option in regionprops to the Green’s Theorem method done. Anyway, after further searching, I decided to ignore the cracks or the waterways in the image and separate first the biggest area in Figure 9 c), which is the largest connected component in figure 11 b). The theoretical area used was obtained from the area feature in Google maps, figure 10, which shows the area of a selected region. I slightly cleaned the results obtained from the edge detection technique as shown in figure 11 c), by removing the points where the radius is less than 400 pixels, to remove the lines inside. This critical radius was obtained from the shortest among half the difference of opposite points along the edge. The summary of the results comparing the area obtained from Google Pro, Green's theorem, morphological operation and region props is shown in the table below. 

Google Pro (sq km)
Green’s Theorem
Sum of White Pixels
RegionProps Area
Area (sq km)
Difference (%)
Area (sq km)
Difference (%)
Area
Difference (%)
221.54
214.58
3.14
210.52
4.97
213.65
3.56


Figure 10. Area of a selected region in Google Maps can be obtained my right clicking, selecting measure distance, and selecting a closed area by selecting points around the curve. 

Looking at the summary of the results of different methods, the Green's Theorem method is pretty good. Though, a lot of modification was done in the image before the method, we still successfully did everything using image processing without human intervention using GIMP. For the whole activity, I give myself 11/10 since I completed the whole activity and added an additional process which is the image segmentation. Though the image segmentation still needs a lot of improvements, I think it is enough since the accuracy of the area estimation technique is high.

Figure 11. The Region of Interest. a) The cluster 3 obtained from figure 7 as shown in figure 8. b) The grayscale image to be used to isolate the biggest connected component which is the region of interest. c) The edges of the region of interests shows edges inside of the larger circle. 


The hand is the cutting edge of the mind -Jacob Bronowski

Martes, Agosto 22, 2017

Masked Figures: Scilab Basics

I was struggling to find how to turn off the axis and change the aspect ratio of the figure. given that scilab has poor documentation, the task was twice harder. After more than a week of pressure, I finally learned how to do it. Hahaha. The code is shown in figure 1.

Figure 1. Code for setting tick marks off

For the activity,we were tasked to try basic matrix operations in scilab such as matrix multiplications, element wise operations, or creating masks to simulate images from matrices. One of the key knowledge here is the use of masks to multiply to matrices to be able to have the desired look of the image. The example code produced an image with a centered circle.

Figure 2. The code for a centered circle with black background
From figure 2, the first parts of the code created a grid for the matrix of the image. Scilab works mostly with matrices so in this case from line 2, x, which is an 1 by 50 matrix was made into X, a 50 by 50 matrix using the function ndgrid. ndgrid is like the meshgrid function in python where it outputs X whose columns have similar elements and rows of varying elements such that 1st column has all 1s and 1st row has 1, 2, 3, .... The Y has rows of similar elements and columns of varying elements. From line 5, r produced concentric circled of different radius depending on the x and y values. So, throughout the activity, the matrix A whose initial values are all zeros, will be used as the base matrix to produce the synthetic images. For the centered circle, a mask for A was used pointing to the region of interest, which is the area r < 0.5 to create a circle of radius 0.5. This was done using a condition for A and changing the element values of A to 1. The next lines of the code are for creating the window where the figure will be shown. f = scf() creates the figure window and f.color_map changes the rendering of the images from numbers to pixel colors. xs2png saves the image.
Figure 3 shows the desired image(left) and the 3D projection of the image(right) where the values of the matrix elements are represented by the z-axis values. In this case, the white pixels in the image has a value of 1 in the z-axis of the 3D projection. The 3D view will be used to confirm if the xy-view of the image corresponds to the required output.


Figure 3. A centered circle (left) and the mesh of the image showing the 3D view where the z axis are the colors of the image(right) showing a cylindrical object

Figure 4. The code for creating a centered square aperture where a mask was used to create an aperture with a value of 1. 

To create the square aperture, the X and Y matrices can be used by just creating an AND condition using &. Without the &, a cross will be produced since for example in the X condition, the Y coordinates of the elements will not be considered. It can still work however by adding additional lines. So far, this is the shortest was I can think of consisting of 2 lines for the mask. The reformulation of the X and Y matrices using absolute value was used so that fewer lines will be need to produce a centered square with the center at 0,0.
Figure 5. Centered square aperture(left) and the mesh of the matrix(right) where the white pixels has values of 1 in the z coordinate similar to a box.

Figure 6. The code for creating a matrix with a sinusoid along the x-direction similar to a corrugated roof

For the corrugated roof along the x-direction, the sinusoidal mask was multiplied to the matrix A, which is a sin of the X matrix. This creates a matrix with sinusoidal row elements. Figure 7 shows a corrugated roof and the sinusoidal shape was confirmed by the 3D perspective. A cute variation can be done by multiplying a mask that is changing along Y.

Figure 7. Sinusoid along the x-direction similar to a corrugated roof (left) and the 3D perspective of the matrix showing the undulation along the x-direction. In the figure, the reference x-axis was labeled Y by scilab. X-axis refers to the horizontal. 
Figure 8. The code for creating a grating along the x-direction. 
For the grating, the previous sin function was used with an added condition to binarize the image by making the values 1 when greater than a threshold and 0 when less. The threshold can be varied to change the grating width. Figure 9 shows the output image with a square wave when projected in 3D.
Figure 9. Grating along the x-direction (left) and the 3D perspective of the image(right)

Figure 10. The code for an annulus created by a circle masked with a smaller circle
For the annulus, the previous method of making a centered circle could be done but now, using 2 circles with different radii. The difference will determine the thickness of the annulus. The image produced in figure 11 shows a hollow cylindrical object when projected in 3D.
Figure 11. White annulus (left) and the 3D perspective showing a hollow cylindrical object (right)

Figure 12. The code for creating a circular aperture with graded Gaussian transparency. 
For the circular aperture with graded transparency, the code for the centered circle can be used. However, a 2D gaussian mask should be multiplied with the base matrix A first before obtaining the circular aperture. In my case, I started with a matrix of 1s and multiplied a gaussian along X and along Y. This created a 2D gaussian surface. Then, the elements greater than the desired radius could be rewritten as 0 to give it color black. Figure 13 shows the output image with the center having the whitest color and the 3D projection similar to a dome, or a fluffy chiffon cake. The output image will be dependent on the mu, sigma, and the radius of the desired aperture. Variations can be done by changing mu to a non zero value or using a different mu and sigma along x and along y, crating a lopsided transparency, or a lopsided dome for the 3D projection. The sigma could also be given a value that is a function of the radius to adjust the transparency while varying the radius similar to that of a lens.
Figure 13. Circular aperture with graded or Gaussian transparency (left) and the 3D perspective showing an object similar to a dome (right)

Figure 14. The code for creating an ellipse using  the formula for an ellipse

For the ellipse, the equation for the ellipse was used and the condition for extracting an ellipse was done similar to that in the case of the centered circle. The image is dependent on the center and the denominator in the equation used. In my case, I used 0,0 as the center and 3 for the x and 4 for the y, creating an ellipse elongated along y. 

Figure 15. Ellipse (left) and the 3D perspective (right) showing an image similar to a leche flan

Figure 16. The code for creating a cross at the middle of the image
For the cross, a conditional similar to the centered square in figure 4 can be used, but this time, the ampersand was not used anymore. The two conditions, along x and along y, was separated as shown in lines 10 and 11 in figure 16. This creates a long cross with ends not detected by the frame of the image. To make is neater, with the edges seen, additional conditions was added which turned the values beyond the edge back to their original values, in this case is 0. The thickness and the length of the cross can be adjusted by changing the values inside the conditionals in lines 10 to 13 in figure 16. The cross can also be tilted by multiplying the X and Y matrices by some sinusoidal value. The center can also be shifted by changing the range of the x and y arrays.
Figure 17. White cross (left) and the 3D perspective (right)

For the whole activity, the pixel size of the images affects the quality of the rendered figures. This is due to the colormap used since scilab tend to connect neighboring pixels by getting the average value of the two neighbors. For example instead of showing the edge between black and white, gray pixels was shown to connect the discontinuous black and white neighboring pixels. For better visualization, a larger pixel size should be used. 

Exploration

For the exploration, I recreated the current logo of the Instrumentation Physics Laboratory, National Institute of Physics, UP Diliman. Looking at figure 18, the logo is made up of circles and half circles making it a bit easier to be reconstructed using basic shapes and masking. With a closer inspection, the shapes in the logo can be divided into similar circles of 4 different radii. The circles with the smallest radius are the grayscale circles at the left most. The x- coordinates of the center of the circles are the same. The next group are the RGB circles with the same x-coordinates for the center. The semi-circles representing concave and convex lens can be done using two circles of the same radius which are spliced for the half of the x-values. The last circle, which is the black sphere, has same radius with the lenses and same y-coordinate for the center with the lenses and the green circle. To make things easier and to avoid trial and error, I used a reference image, which is shown in figure 18, and obtained the center and radius by getting the pixel coordinates of certain points in the figure(such as the centers of each circle, an edge of a circle for the radius, etc) using paint same as what was done in the previous activity. 

Figure 18. The IPL logo taken from the cxteam.liknayan.com to be used as reference for the exploration part of the activity

So, for the reconstruction, I created 10 circles of different centers. For example, for a circle c = sqrt((X - centerx).^2 + (Y - centery).^2)will create a matrix of concentric circles centered at the center of the circle c, where centerx and centery are the x and y coordinates of the center of the circle c. 
 The base matrix will be matrix A of zeros similar to that in figure 2. The masks for each circles was done by making the elements of A when the value of the c is less than radius of the circle c be equal to a certain value unique for that circle. Example: A(find(c < radiusc)) = uniquevalue. the radiusc is the radius of the circle c and uniquevalue can be any number not equal to the original elements of the matrix A. For the lenses, which are half circles, an additional condition was added to locate only the other half of the circle. The initial output is shown in figure 19. 
Looking at the original logo however, the background is white. Since currently, the graycolormap(32) is being used, the higher numbers pixels will be colored white. So from the initial matrix A, instead of zeros, the value can be any number that is not the value of the circles. In my case, since there are only 9 unique colors (since the lenses have the same colors) 10 can be a safe value of the original matrix. It can be done by making the original matrix 1s instead of zeros using ones() and mutiplying element wise to 10. A = ones(nx, ny);A = A.*10. The resulting figure is shown in figure 20. The values of the circles were also adjusted for it to match with the original logo. 
Figure 19. The initial output for the recreation of the IPL logo with a black background and grayscaled circles or varying values.
Figure 20. Reconstruction of the IPL logo with a white background and grayscaled circles of varying values to mimic the actual look of the logo

To increase the details of the logo, the color_map used can be adjusted to mimic the colors of each circles in the logo. For this, I used the RGB values (closest to the original logo I could get) of each circle and used it as the color_map of the figure. Since the RGB has values from 0 to 255, the RGB values was divided by 255 for the value of the color_map be from 0 to 1. The cmap are 9 RGB values and the value of the circle are based on the index of its RGB color in the cmap. For example, the RGB value of the circle c is the 5th RGB value in the array cmap, so the circle c was given the value 5. The resulting image is as shown in figure 21. The complete code for the whole recreation of the logo is shown in figure 22. 
Figure 21. Colored IPL logo done using color_map by specifying the RGB values of the circles


Figure 22. The final code of reconstructing the IPL logo using different circle masks and specified RGB values of each circle for the colormap 

I find the whole activity quite fun especially since relatively complex shapes were produced from basic shapes. I would give myself 12/10 for this activity since I was able to produce all the required output and I successfully understood the basic scilab operations, the images are of good quality and properly labeled, and I was able to do the exploration part plus I used the previous lesson of obtaining pixel locations and I was also able to use manipulate the desired color of each mask. 

For the whole activity, I would like to thank Elijah Justin Medina for sharing his knowledge about color_map, on editing the axes_size, and on placing codes on the blog. Right now, I just placed figures of the screen shot of the codes, which made my blog post kinda messy. I will do the editing of html on my next blog posts for the codes. I would also like to acknowledge Adonis Villagomez and Clauzette Lofamia for telling me about the &, the equation for the ellipse, and other matters about scilab and the whole activity. 

Mortals are equal; their mask differs. -Voltaire