Ipinapakita ang mga post na may etiketa na image segmentation. Ipakita ang lahat ng mga post
Ipinapakita ang mga post na may etiketa na image segmentation. Ipakita ang lahat ng mga post

Martes, Disyembre 19, 2017

Through Rose-Colored Lenses: Color Image Segmentation

For this activity, objects in an image can be detected using its color. This is very easy for humans, now, we will let the computer do it using normalized chromaticity coordinates. The first method is to do parametric segmentation where the value in a gaussian distribution of each pixel was obtained using the mean and the standard deviation of the region of interest. Basically, this shows how is the color of the pixel from the color of the ROI in the NCC plot.  
Non-parametric segmentation uses the NCC plot of the region of interest. For each pixel in the original image, the (r,g) values will be obtained. The frequency of the (r,g) value in the NCC plot of the ROI will the new pixel in the converted image. The converted image will then have white or high pixel values for objects with colors same as in the ROI.


Figure 1. The original image used. 

Figures 2-6 shows different results of segmenting the image using different ROIs. One common observation is that the non-parametric segmentation captures other objects with colors included in the region of interest. The parametric segmentation only objects with colors very near to the color of the region of interest. In figure 2, for example, the parametric segmentation captured brightly the blue logbook only. It faintly detected the blue shirt at the lower left of the image. The non-parametric segmentation also captured the cyan rose notebook and the cyan pen near the center. 
In figure 3, the cyan pen was also detected by the non-parametric segmentation. 
In figure 4, the parametric segmentation detected the red notebook and the pink container at the left. The floor, the umbrella, the roses, and other reddish colors were not detected but were detected using the non-parametric segmentation. 
In figure 5, only the yellow notepad was detected, other instances of yellow were not detected by the parametric segmentation, but were detected by the non-parametric segmentation. 
Figure 6 is a bit hard since the region of interest contains more than 1 color. Focusing on the region of interest, which is the rose notebook, parametric segmentation faintly detected the notebook. Black and white images however were brightly captured even though the ROI is not abundant in black and white pixels. Non-parametric segmentation brightly captured the region of interest and also captures other objects with cyan or red tint. 

For object tracking, parametric segmentation might be more ideal since it only focused on the most abundant color in the object. There is lesser noise in the background. For color tracking however, non-parametric segmentation is better since it detects instances of the colors in the ROI. Parametric segmentation works best when the ROI is monochromatic. For an ROI with more than one color, parametric segmentation detects white or black pixels since it is near the center of the NCC. In this cases, it is better to use the non-parametric method. 

Figure 2. Segmenting the blue logbook. a) The ROI and the NCC histogram. b) Parametric segmentation. c) Using the result of the parametric segmentation as a mask isolates the notebook. d) The NCC histogram of the original image. e) Non-parametric segmentation. d) Non-parametric segmentation as a mask. 

Figure 3. Segmenting the green logbook. a) ROI. b-c) Parametric segmentation. d) NCC histogram of the original image. e-f) Non-parametric segmentation. 



Figure 4. Segmenting the red notebook. a) ROI. b-c) Parametric Segmentation. d) NCC histogram of the original image. e-f) Non-parametric segmentation. 

Figure 5. Segmenting the yellow notepad. a) ROI. b-c) Parametric segmentation. d) NCC histogram of the original image. e-f) Non-parametric segmentation


Figure 6. Segmenting the Rose notebook. a) ROI. b-c) Parametric segmentation. d) NCC histogram of the original image. e-f) Non-parametric segmentation. 

For this activity, I give myself 10/10 since I completed the whole activity. I would also like to acknowledge Rey and CJ for the image used, which is the image we used for a group activity in 187.


No matter what anyone says or does, my task is to be emerald, my color undiminished - Marcus Aurelius

Lunes, Disyembre 11, 2017

Moment Frozen in Time: Basic Video Processing

The last 186 activity for me is the one big aspect of image processing. It comes from the idea that a video is a series of images. Individual image processing of each frame in a video is video processing. In this activity, we were tasked to do a common physics experiment done in video and do the analysis using image processing of the video frames.
For each video, it is vital to know the frame rate of the video, or the number of frames flashed per second, especially when temporal information is needed. The ideal frame rate to prevent lost of information is based on the Nyquist Criterion. 
For this activity, we did a classic physics free fall experiment, which we all know by heart. A video captured a free falling tennis ball for 29.97 frames per second. The frame rate is okay since there is no repetitive motion. 

In the experiment, the acceleration due to gravity can be measured by obtaining the change in speed of the tennis ball over time. To do this, the location at every instant of the tennis ball should be obtained. 

From the video, image segmentation was used to locate the tennis ball using the ROI from the surface of the tennis ball at one frame. Since this is a video, the quality of each frame depends on the frame rate. Most of the frames made the ball look blurry especially towards the end where the speed is increasing. Seen in figure 1, at frame 50, the ball is so blurry and is almost unseen. With this, care should be taken when choosing the ROI. When an ROI is from a frame where the object is not yet moving, the ball gets undetected at a later time since the ball blurs. In my case, the ROI is from frame 47 since the color captures the motion of the ball but is not so blurry that the background would be selected. Further improvement in the tracking is done using morphological operations. Regionprops was used to detect the centroid of the ball, which tells the approximate location at that frame. 

Figure 1. Frames 47 and 50 of one trial of the free fall video. 



The videos below show one of the trials done. The center of the white blobs show the pixel locations of the ball, which was converted to actual coordinates from the pixel length of the protractor which is 12.5cm. The corresponding frame at which the ball was located was also converted to real world time coordinates from the frame rate property of the video. 




The tracked positions of the tennis ball for 4 trials are shown in figure 2. The speed is shown in figure 3. The position was adjusted so that the floor is at 0m. This adjustment is needed since the pixel convention is increasing from top to bottom. From the curve fit of the trajectory, the acceleration due to gravity has the values of -8.37 m/s2, -9.22 m/s2, -10.11 m/s2, and -9.45 m/s2. The obtained values are near the accepted value. Deviations from the measurement could be due to the blurring of the ball while in motion. From the velocity plot however, shown in figure 3, the acceleration values are 9.79m/s2, 9.73 m/s2, 7.18 m/s2, and 7.96 m/s2. For each trial, the obtained value if different for the two plots. The lines in figure 3 however do not fit well as shown by the r2 values from 0.6 to 0.7. For trial 2, shown by the orange plots in figures 2 and 3, the obtained values for the acceleration are close to each other, which is 9.22 m/s2 and 9.73 m/s2. Interestingly, the r2 of the fit in the velocity plot is 0.93, which is close to 1. Interestingly, the obtained values for the acceleration. The disparities of the computed values could be due to the blurred motion of the ball caused by the limitation of the camera and the video's frame rate. 

Figure 2. The position vs time plot of the tennis ball in free fall. Curve fitting gives the value of acceleration of -10.11 m/s2 to -8.37 m/s2

Figure 3. The velocity vs time plot of the tennis ball in free fall. Linear regression obtains the acceleration values in the range of 7.18 m/s2 to 9.79 m/s2.

I really like this activity since in some of our Physics 19x experiment, we were forced to do image processing for the data analysis due to the limited working lab quest available. I had fun in video analysis and object tracking since some of the data, such as the swinging of the pendulum, or the collision of two objects, etc, are hard to see using the naked eye, but is very observable when the videos are sliced into frames. 

For future work, it would have been more fun to do some pendulum experiment such as the energy transfer experiment in 191. This experiment requires focus from the experimenters since the amplitude of the pendulum swing varies and some set-up has very fast energy transfer. It is also hard to use a motion detector for this since there are two pendula and their sync is essential. Also, with pendulum experiments, only the frame rate is important for conversion to real world coordinates. The pixel to real world distance is most of the time not needed. 

For this activity I failed to do an additional exploration part due to the limits of time. However, in my future works, I will still do more object tracking and video analysis. It also took me a little longer than expected to finish this activity since the ruler, seen in figure 1, gets segmented with the tennis ball, and it took me a while to solve the blurring of the ball, which made it undetected. Despite that, I think I perfectly understand the concepts needed for this activity, and the plot and videos are good. I also had a few practice with using videoWriter() function and in obtaining a good frame rate but I turned the video into a gif file since blogger lowers the quality of the video. So I give myself 10/10 for the evaluation. 

I would like to thank Nica and ate Clei for letting me help in the acquisition and sharing with me the experiment video. I also acknowledge all the other people who helped me learn things in this 186 course, which I used in finishing this activity. 

It does not matter how slowly you go as long as you do not stop. -Confucius