Due: Wednesday 1/14 10:00am
Submission name: work37.nlogo
Like yesterday, you will be using patches in NetLogo to represent images, this time with some other procedures. You should add these to yesterday’s assignment. Recreate the NetLogo program found here: http://homer.stuy.edu/~dw/netlogo/img/images_obf.html
World State:
We want 1 patch to be equal to 1 pixel to do that:
- Set the origin to the bottom-left corner.
- Set the size to 640 x 480 (or whatever the resolution of your source image is)
- Set the patch size to 1
Patch properties
Give patches 2 properties to be used in your procedures:
start_color
next_color
Procedures
horizontal_flip
- Flip the orientation of the image horizontally.
vertical_flip
- Flip the orientation of the image vertically.
mirror
- All the patches on the right half of the image should change color the same way they do for
horizontal_flip
- All the patches on the left half of time image should not change.
edge_detect
- For this, add a new patch property called
color_difference
- Useful background information:
- When given an agentset
of
will return a list of values.- i.e.
[color] of turtles
will return a list of colors (one entry per turtle)
- i.e.
sum
is a NetLogo procedure that will return the sum of the values in a list.
- When given an agentset
- We can determine if a patch represents an edge in our image by comparing its color to the colors of its neighbors. This is called edge detection. One common edge detection algorithm works as follows:
- Grayscale the image (this removes color information but retains shape information of an image)
- Find the average color of the pixels surrounding a given pixel.
- Find the (absolute value) difference between the color of a pixel and the average color of its surrounding pixels.
- If the difference is above a set threshold value, then the pixel must be on an edge, otherwise its not.
- Make all the “edge” pixels one color (i.e. black) and all the non-edge pixels another (i.e. white)
edge_detect
should run the algorithm explained above. Some things to play with:- Different definitions of “surrounding” patches.
- Using a slider for the threshold value.
- Using calculations other than average and difference.