Edge detection

I’ve been looking into edge detection in Python and it seems that the simplest way to achieve this is to have an image with blacks and whites as the main components. After reading through some websites with some examples it seems that although it does seem possible to apply it to color images, it seems to get much more complicated rather quickly. I found a piece of code that scans an image and detects pixel values and one could make it so that the program would go through the image from top to bottom thus mapping the location of each point that represents a boundary from black to white and use that to make an outline of said edge. This shape could be stored as a vector and then the vector could be used to calculate the angle in the detected edge region (tying back into my angle of repose project).

From: http://lu-vision-dock.blogspot.com/2009/04/sobel-edge-detection.html

def sobel(img):
if img.mode!= "RGB":
img = img.convert("RGB")
out_image = Image.new(img.mode, img.size, None)
imgdata = img.load()
outdata = out_image.load()

gx = [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]
gy = [[-1, -2, -1], [0, 0, 0], [1, 2, 1]]

for row inxrange(1, img.size[0]-1):
for col inxrange(1, img.size[1]-1):
pixel_gx = pixel_gy = 0
pxval = sum(imgdata[row,col])/3
for i inrange(-1, 2):
for j inrange(-1, 2):
val = sum(imgdata[row+i,col+j])/3
pixel_gx += gx[i+1][j+1]* val
pixel_gy += gy[i+1][j+1]* val
newpixel = math.sqrt(pixel_gx * pixel_gx + pixel_gy * pixel_gy)
newpixel = 255 - int(newpixel)
outdata[row, col] = (newpixel, newpixel, newpixel)
return out_image

This is still pretty new to me and I’ve yet to wrap my head around that the math is actually doing but I think vectors are a good way to go with this one. Should be fun.

Aside from this there are a lot of actually dedicated image processing modules out there which I’ve yet to look into thoroughly. It’s likely that one of them contains something that will simplify what I’m trying to achieve so I’ll get to looking into those as well.

A couple of promising prospects are OpenCV and Scikits-image (adds image processing functionality to SciPy). Scikits-image has some particular examples which are very interesting and can probably be put to use in what I’m trying to achieve.

http://scikits-image.org/docs/dev/auto_examples/applications/plot_coins_segmentation.html

http://scikits-image.org/docs/dev/auto_examples/plot_contours.html

http://scikits-image.org/docs/dev/auto_examples/plot_canny.html

http://scikits-image.org/docs/dev/auto_examples/plot_watershed.html

Video of the fine grain lactose which had a smoother flow to it once it had been “fluffed.”

Video of the “Chunky” lactose forming a mound as it fell from the cylinder. Notice how I had to tap the cylinder to get it to come out and it still didn’t flow out smoothly.

Just some samples from a few trials I did yesterday and today. These show some piles formed by the fine powdered lactose. I tried to replicate an effect Dr. Smyth mentioned about rippling when the powder is let fall down. Although I could kind of see it start to happen in the second to last photo, I really need to make something that can hold the funnel and has a removable piece to let the powder out. I’ve some ideas which I’ll get to working on soon.