Finding a Position Within an Image

Community Forums/General Help/Finding a Position Within an Image

feeble1(Posted 2014) [#1]
Does anyone know of a method to find a point within a dynamic image?
Essentially, I want to draw another image on top of another image. Like drawing a hat onto a stick figure. But I would like the stick figures head to be in different positions in multiple images and still be able to find it.
I have been scratching my head quite a bit.


Derron(Posted 2014) [#2]
a) write an algorithm scanning the image for certain "objects" - if you know the "head" is a circle - you search an y-line with "black", the next y one has to have a "longer black line", ... and so on, after a certain point, it must decrease in length. As soon as your "rules" do not fit - this isn't the circle you are looking for. This approach is way more straightforward and effective for reading ninePatch markers

b) define the position and type of the object in the image somewhere ... so "head in image Z at x,y with radius r"

ladder one is the one to go for you.


bye
Ron


feeble1(Posted 2014) [#3]
Thanks again Derron.

Right now I'm attempting to readpixel to find a single green pixel at the top of the head.


Shambler(Posted 2014) [#4]
Make a pixel at the top of the head a specific unique colour in the image then search for that.

You only have to make it a slightly different colour, not so much that it stands out visually.


Derron(Posted 2014) [#5]
This "slightly different colour" approach is what I am using to:

- colorize sprites according player colors: I replace all "gray"tones with a colorized ones. To avoid not-to-color-"gray elements", I made them slightly "blueish"

@feeble:
just loop through the pixel data and stop as soon as you find the pixel you want. (easy: 2 for loops for x and y: ColorInt = ReadPixel(pixmap, x,y) )


bye
Ron


TomToad(Posted 2014) [#6]
If you are creating the images yourself, you can always store the x,y coordinates somewhere. Possibly an extra file with the information needed. Or you can store the information in the image itself. If you are using alpha to draw the image onto a background, most likely the upper left corner will have an alpha of 0. You can store the x and y position of the head there.

in your stick figure editor:

in your stick figure game:


BigEndian() is a function that will take an Int and convert it to Big Endian if you are on a system with little endian. If the number is already big endian, it will convert it back to an int. This is necessary as the alpha channel is the high byte of the pixmap.


feeble1(Posted 2014) [#7]
I have heard much talk of big and little endian. I really need to read up on that!

Thank you very much for all your help.