I have an interesting problem. I've got an application which generates a sort of Heightmap based on an image as such:

https://imgur.com/a/hRcvc

I have been trying, for awhile now, to think of a way I could create an algorithm to analyze the shape of the anything above a certain Z-Axis level.

My ultimate goal is to determine how irregular the shape is by comparing the image to a rectangle and returning an integer (From 0-1) based on how similar the white object is to a rectangular box. Or I suppose, from the algorithm's point of view, how many straight edges are present in the image.

Currently, I generate the heightmap to get X, Y, and Z as such:

Private zData(,) As Single For y As Integer = 0 To bmp.Height - 1 For x As Integer = 0 To bmp.Width - 1 zData(x, y) = bmp.GetPixel(x, y).GetBrightness Next Next

**And for Z:**

For y As Integer = 0 To data.GetUpperBound(1) For x As Integer = 0 To data.GetUpperBound(0) minZ = Math.Min(zData(x, y), minZ) maxZ = Math.Max(zData(x, y), maxZ) Next Next

So far, I'm thinking I'd linearly parse the entire image (or array of values) along the Y-Axis, and determine how many points along the Y-Axis contain a value of Z >= 0.5 (or whatever value I am wanting to find). However many hits it gives me in a row will contribute to how linear the image is along that axis, and then again along the X axis?

Problem with that idea is 2 things:

I can't wrap my head around if that would be accurate enough

I am not sure how I can write a loop which can do this

Any ideas, or guidance would be extremely appreciated!