Finding connected components was the most challenging part of this assignment. At first I tried implementing a recursive algorithm, but my stack was overflowing. So I decided to implement the iterative labeling algorithm, however this DID NOT WORK. So I went back and tweaked my recursive algorithm until it worked. Here is an outline of what it does.
Scale the image to prevent stack overflow
Threshold the image based on image group (bats, hands, lung, etc. are thresholded on a different value)
The thresholded image has a 255 for background and a 0 for foreground
Start a region counter to 1
Create a vector to store neighbors
Iterate through every pixel in the image
If a black pixel is found
Color it with the current label
Find its neighbors and color with current label
Find neighbors of neighbors recursevily until no more neighbors found
Keep iterating through the image
Orientation, Centroid, and Circularity
All these quantities qere calculated image moments as described here
Experiment and Results
Tumors in the lung
This was probably the most challenging part of the homework in terms of figuring out a way to make it work. There were may challenges, the biggest being the similarity in intensity values of the tumor with the outside component of the lungs. This similarity made it impossible to have a labeling algorithm that would not overflow without downscaling so much the tumors dissaperared. I solved this problem by cropping the image on the region of interest (inside the lungs).
Thresholded image
Labeled Image
Processed Image with tumor highlighted in red
Flying Bats
This part was fairly straight forward. Once I found a nice threshold value for the bats, I ran the labeling algorithm. Once all the bats were labeled I ran the orientation algorithm, and drew a line showing the direction of flight.
Thresholded images
Labeled Images
Processed Image with orientation drawn in red
Pupils in the eyes
Also very much without problems. Once a nice threshold was found, I found the centroid of the largest region and drew a circle that matched the area of such region.
Thresholded images
Labeled Images
Processed Image with pupil highilghted in green
Chosing the open hand
Fairly complex algorithm to implement. First I found a nice threshold. Then found the regions in the image. I proceeded to filter the regions by area, and found the circularity of each area. If the circularity met a certain threshold, I marked the hand as open, otherwise as closed.
Thresholded images
Labeled Images
Processed Image with open hands marked blue, close hands marked red
Motion of Cells
Very similar to the motion of the bats, except it didn’t work as nicely.
Thresholded images
Labeled Images
Processed Image with orientation drawn in red
Discussion and Conclusion
Tumors in the lung
Didn’t work so well. Mainly because the labeling algorithm will overflow for large regions.
Flying Bats
This was fairly accurate, it identified the bats pretty well and was able to correctly determine their derection of flight. There was one bat that was too small and the algorithm missed him.
Pupils in the eyes
Not too bad overall, however shadows and other dark objects greatly affeted the performance of this algorithm.
Chosing the open hand
Probably the most accurate algorithm of all. Place the correct colored fot on the hand that was open.
Motion of Cells
Worked very nice except for cell 3. It thought it was moving in the opissite direction. The other two cells it identified correctly.
Image Identification
This programs does many things:
Finding Regions
Finding connected components was the most challenging part of this assignment. At first I tried implementing a recursive algorithm, but my stack was overflowing. So I decided to implement the iterative labeling algorithm, however this DID NOT WORK. So I went back and tweaked my recursive algorithm until it worked. Here is an outline of what it does.
Orientation, Centroid, and Circularity
All these quantities qere calculated image moments as described here
Tumors in the lung
This was probably the most challenging part of the homework in terms of figuring out a way to make it work. There were may challenges, the biggest being the similarity in intensity values of the tumor with the outside component of the lungs. This similarity made it impossible to have a labeling algorithm that would not overflow without downscaling so much the tumors dissaperared. I solved this problem by cropping the image on the region of interest (inside the lungs).
Flying Bats
This part was fairly straight forward. Once I found a nice threshold value for the bats, I ran the labeling algorithm. Once all the bats were labeled I ran the orientation algorithm, and drew a line showing the direction of flight.
Pupils in the eyes
Also very much without problems. Once a nice threshold was found, I found the centroid of the largest region and drew a circle that matched the area of such region.
Chosing the open hand
Fairly complex algorithm to implement. First I found a nice threshold. Then found the regions in the image. I proceeded to filter the regions by area, and found the circularity of each area. If the circularity met a certain threshold, I marked the hand as open, otherwise as closed.
Motion of Cells
Very similar to the motion of the bats, except it didn’t work as nicely.
Tumors in the lung
Didn’t work so well. Mainly because the labeling algorithm will overflow for large regions.
Flying Bats
This was fairly accurate, it identified the bats pretty well and was able to correctly determine their derection of flight. There was one bat that was too small and the algorithm missed him.
Pupils in the eyes
Not too bad overall, however shadows and other dark objects greatly affeted the performance of this algorithm.
Chosing the open hand
Probably the most accurate algorithm of all. Place the correct colored fot on the hand that was open.
Motion of Cells
Worked very nice except for cell 3. It thought it was moving in the opissite direction. The other two cells it identified correctly.
Source Code