1

So I have this bit of code

for x in range(x1,x2):
        for y in range(y1, y2):
            cpixel = pixels[x, y]
            if bw:
                bw_value = int(round(sum(cpixel) / float(len(cpixel))))
                all_pixels.append(bw_value)
                title = "Averaged (B&W) Pixel Values"
            else:
                if lumi:
                    luma = (0.3 * cpixel[0]) + (0.59 * cpixel[1]) + (0.11 * cpixel[2])
                    all_pixels.append(luma)
                    title = "Pixel Luminosity Values"
                else:
                    if round(sum(cpixel)) / float(len(cpixel)) > 100:
                        all_pixels.append(255)
                    else:
                        all_pixels.append(0)
                    title = "Pixel Binary Transform Values"

taken and modified a bit from here Getting list of pixel values from PIL to give a list of pixel values (all_pixels) within a bounding region (user selected).

I'm trying to figure out an efficient way to detect changes within the list after a series of similar values have been recorded. Since the list seems to list the pixel values from top to bottom and left to right. In the scenario I will be using it in, it'll have a list of similar values until it hits a region of an image where the values will then begin to switch back and forth until the values once again stabilize around a new value.

What I'm interested in is tracking the boundary between these two, I want to detect where this boundary is and if it shifts left or right. I can't really think of any other way than having to check each value as it's appended to all_pixels and then just tracing back the coordinates.

But even this seems rather sketchy since even if I set an arbitrary number of values to be the same before the next one that's significantly different is seen as a significant change, not just an outlier, after that the values begin to toggle between the old values and the new ones.

I guess ideally I'd need to generate some sort of best fit line for the coordinates of this boundary region/line. I just need some ideas how to approach this problem.

Community
  • 1
  • 1
DamianJ
  • 419
  • 2
  • 8
  • 18
  • 1
    What exactly do you mean with 'significant change'? And what is it for? It sounds like you want to do some kind of motion tracking. – Junuxx Jun 14 '12 at 02:44
  • Indeed, basically I have a powder in a cylinder and I want to track it's volume as it compacts after being tapped. The "boundary I speak of is the line of the top of the powder produced by it's shadow. So significant would be any value greater than that produced by the shadow region. Basically I take an image after each tap and that's how i'm trying to track it's change. – DamianJ Jun 14 '12 at 02:47

2 Answers2

1

Based on the description of the problem in your comment, I think a simple edge detector might suffice, although that would depend on things like the camera angle, contrast, lighting, etc.

You could take the vertical derivative of the image, possibly smooth that a bit and find the row with the highest values. Assuming that the image is zoomed in on the cylinder with no other major vertical contrasts other than the powder boundary, that should be the height of the powder.

You could code this yourself, or use OpenCV, but I think that might be a bit overpowered for this task. Numpy would also be a good option.

Junuxx
  • 14,011
  • 5
  • 41
  • 71
0

From your description, it sounds like you should really just be using a computer vision library, rather than trying to write your own image detection code.

Here's a discussion of computer vision in Python: What is a good computer vision library for Python that will allow me to me to find faces in a Flash/HTML5 video?

It sounds like OpenCV is the best bet.

http://opencv.willowgarage.com/

Community
  • 1
  • 1
steveha
  • 74,789
  • 21
  • 92
  • 117