SRL Archive - Help and Support

Removing outer pixels from TPA


Frement

2010-12-17 07:16:19

How would I go if I wanted to delete outer points from a TPA?

Heres an image:

The red line, is what I want to remove (lets assume its 1 pixel), and the white is what I want to keep, black ofcourse is the background, and doesn't concern this problem.

Wizzup?

2010-12-17 07:28:10

White and Red are in the TPA? If so, the easiest way would be to loop over the bitmap. Say from left-right, top-bottom. Remove the first point and the last point you encounter on each line. That should do it. Unless you have more than two points on the line, which isn't the case in this figure.

Other methods would be to split it up in lines w/ degrees, sort by distance and remove the last point. But that's probably slower and harder. It also depends on the object you're analysing. I just woke up, perhaps I'm missing a more obvious method atm. ;)

Frement

2010-12-17 07:41:06

The problem is, I don't have the bitmap, I need to solve this with the TPA. Is there a way I can sort the TPA into ATPA (Isn't ATPA just Array of TPointArray?) horizontally.

Like: ATPA[0] = First horizontal points from top etc…

Wizzup?

2010-12-17 08:58:26

From: Frement
The problem is, I don't have the bitmap, I need to solve this with the TPA. Is there a way I can sort the TPA into ATPA (Isn't ATPA just Array of TPointArray?) horizontally.

Like: ATPA[0] = First horizontal points from top etc…


Turn it into a 2D boolean array. (true = point in TPA, false = point not in TPA)
I think Wizzyplugin has functions for it. I've used this in a lot of places.

Then, for the boolean array:

for x := 0 to length(b)-1 do
// this is one line
for y := 0 to length(b[x])-1 do
// one pixel

Frement

2010-12-17 11:18:50

From: Wizzup?
Turn it into a 2D boolean array. (true = point in TPA, false = point not in TPA)
I think Wizzyplugin has functions for it. I've used this in a lot of places.

Then, for the boolean array:

for x := 0 to length(b)-1 do
// this is one line
for y := 0 to length(b[x])-1 do
// one pixel


I forgot to mention, I'm coding this in C++, so I'm not using wizzyplugin :(

I'll figure out a way to do it.

lordsaturn

2010-12-17 14:46:57

Well if you're coding in c++, I would use oop to it's full potential and create a class to do this for me. All of the solutions I came up with could be bettered by oop.

n3ss3s

2010-12-17 15:58:56

What I would do is arrange them into a 2D array (a for loop for the assumed height of the tpa, which has another for loop inside checking if the current point we are observing is the same height as the current int of the height loop, if so, slap into the array in the 2d array that's [currentheight]).

Then all you need to do is go through each array of the 2D array, and add all the points into a new single array, omitting the first one, and setting the length of the array for this height 1 less than before so it automatically deletes the last one.

Wizzup?

2010-12-17 18:16:47

From: Frement
I forgot to mention, I'm coding this in C++, so I'm not using wizzyplugin :(

I'll figure out a way to do it.


Well turning it into a boolean array is easy. You can even just make it a 1D array. Position is y*height+x, etc.


xx, yy = box of tpa
boolean array length = xx * yy
for tp in tpa:
boolean array[tp.y * yy + tp.x] = true

2d is even more straighforward


for tp in tpa:
b[tp.x][tp.y] = true

Frement

2010-12-18 03:47:08

Thanks everyone for posting, I now understand how to this, thanks :)

Wizzup?

2010-12-18 05:43:31

From: Frement
Thanks everyone for posting, I now understand how to this, thanks :)


Care to share? Because I'm not sure my algorithms will work for everything. :)

nielsie95

2010-12-18 07:20:23

You could also use an edge detecting algorithm and delete the edge (or invert the return of the edge detecting).

Wizzup?

2010-12-18 09:03:04

Actually, I'm pretty sure WizzyPlugin has functions for it since we used this in FindTalk, FindTPAinTPA, etc.