Lab 9: Computer Vision
Lab 9: Computer Vision
NetID:
In this lab, we will have a look at a couple of simple examples of image processing for computer vision.
Run each line of code in each section and observe their effects on the image inputs.
Part 1
Part 1
A Few Basic Image Processing Operations
A Few Basic Image Processing Operations
ColorQuantize
ColorQuantize
ColorQuantize reduces the number of distinct colors in the image:
In[]:=
ColorQuantize
,3
In[]:=
ColorQuantize
,5
Quantize using a specific list of colors:
In[]:=
ColorQuantize
,{Black,Purple,Green}
DominantColors
DominantColors
DominantColors returns dominant colors in .
image
DominantColors
Separate an image into the regions of its dominant colors:
DominantColors
,Automatic,{"CoverageImage","Color"}
Binarize
Binarize
Binarize creates a binary image: every pixel above a threshold value is 1 or white and every pixel below is 0 or white.
Binarize
Try this fun example:
In[]:=
BinarizeGradientFilter
,1,Method{"BlackFraction",.8}
EdgeDetect
EdgeDetect
EdgeDetect finds edges in and returns the result as a binary image.
image
In[]:=
EdgeDetect
Problem 1
Problem 1
Use an image of your own choice and apply any two of the four image processing operations you have learned above.
Part 2
Part 2
What does the model see?
What does the model see?
Step 1
Step 1
Check what the image identification machine learning model says about this image:
In[]:=
ImageIdentify
Step 2
Step 2
Now blur the image a bit
In[]:=
blurredImage=Blur
You can use blur as follows, with a number after the comma next to the image, which blurs the image over a pixel radius specified by the number.
blurredImage=Blur
,5
Step 3
Step 3
Now try to identify the blurred image
In[]:=
ImageIdentify[blurredImage]
Problem 2
Problem 2
Keep increasing the pixel radius for blurring till the point when ImageIdentify is no longer able to identify the image correctly. What is the value of the pixel radius when ImageIdentify fails?
In[]:=
Blur
,50
Problem 3
Problem 3
What does the image look like when you blur it to an extreme of say 25 or 50? How does ImageIdentify identify it?
In[]:=
ImageIdentify[]
Part 3
Part 3
Create some pop art with image segmentation algorithms.
Create some pop art with image segmentation algorithms.
Step 1
Step 1
Here is an image:
In[]:=
img=ExampleData[{"TestImage","House2"}]
Step 2
Step 2
The ClusteringComponents function finds clusters of pixels in an image. You can provide the number of clusters you want in the image. The code below will find only 3 clusters, which may not produce a very interesting result.
clusters=ClusteringComponents[ExampleData[{"TestImage","House2"}],3]
The above code finds a bunch of numbers for the image. Uninteresting!! But look what happens when you feed those numbers into Colorize function.
(Colorize generates an image from an integer matrix, using colors for positive integers and black for non-positive integers).
(Colorize generates an image from an integer matrix
m
Problem 4
Problem 4
Use colorize to create a visually interesting output. You will have to increase the number of clusters in step 2 to get more clusters that will be colored differently.
In[]:=
Colorize[clusters]
Extra Credit
Extra Credit
Warning: The video processing code may take a while to run.
Download an example video with the following piece of code:
Extract one frame from the video:
Find ImageBoundingBoxes for objects in the image:
Find ImageBoundingBoxes for objects in every frame of the video:
Problem 5
Problem 5
Download the following video: https://pixabay.com/videos/swans-ducks-water-white-bird-1287/
Import the video. From the menu use Insert -> File Path to find the path to your downloaded file:
Use the code provided earlier to find the bounding boxes for all the swans and ducks on the water:
Comment on how well the algorithm is able to follow the birds as they float on the water.
Submitting your work
Submitting your work
1
. Publish your notebook
1
.1
.From the cloud notebook, click on “Publish” at the top right corner.
1
.2
.From the desktop notebook, use the menu option File -> Publish to Cloud
2
.Copy the published link
3
.Add it to the top of the notebook, below your netID
4
.Print to PDF
5
.Upload to Gradescope
6
.Just to be sure, maybe ping your TA Sattwik on Slack that you have submitted.