Get all pixel coordinates of selection - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions) +--- Thread: Get all pixel coordinates of selection (/Thread-Get-all-pixel-coordinates-of-selection) |
Get all pixel coordinates of selection - joho21 - 09-27-2021 Hello there! I've used GIMP for various different things over time and I've recently been thinking about how to automate some of my image processing needs. What I would like to know: is there an easy way to either get a list of all the XY coordinates of all pixels in a particular selection or, barring that, get the XY coordinates of all the pixels on a given layer? RE: Get all pixel coordinates of selection - PixLab - 09-28-2021 Quote:What I would like to know: is there an easy way to either get a list of all the XY coordinates of all pixels in a particular selection or, barring that, get the XY coordinates of all the pixels on a given layer? I don't see where you want to go with "particular selection". You have multiple selection? Or you want every coordinate of every single pixel? What do you want to achieve by doing so? Please give us a bigger "picture" about what you would really like to do. Speaking about XY https://xyproblem.info/ (thanks to Ofnuts for that link) RE: Get all pixel coordinates of selection - Ofnuts - 09-28-2021 (09-27-2021, 07:37 PM)joho21 Wrote: Hello there! I've used GIMP for various different things over time and I've recently been thinking about how to automate some of my image processing needs. What I would like to know: is there an easy way to either get a list of all the XY coordinates of all pixels in a particular selection or, barring that, get the XY coordinates of all the pixels on a given layer? That would be a huge list... You can get the "bounding box" of a selection, or the origin and size of a layer. You can also get the selection as a mask and get the selection level of any pixel. A last way is to convert the selection to a path, which is described by a few hundred points, and there are algorithms to determine if a point is inside or outside the shape. But as PixLab says, it looks like you are starting in the wrong direction, so what makes you think you need this? What is the original problem? RE: Get all pixel coordinates of selection - joho21 - 09-28-2021 (09-28-2021, 04:02 AM)PixLab Wrote:Quote:What I would like to know: is there an easy way to either get a list of all the XY coordinates of all pixels in a particular selection or, barring that, get the XY coordinates of all the pixels on a given layer? Sure, I can give the bigger picture. I've got a map that will be used for a conflict-type game, hosted by a Discord bot. What I'd like to accomplish is for the different provinces of the said map to be automatically colored based on who owns them. Ie, if one person conquers province 8, province 8 will now be their color. I was looking at using PILLOW, which lets you color images, but only one pixel at a time. I'd have to get a list of all the pixels within the bounds of each province in order to change their color automatically. The difficult part is just getting a list of XY coordinates for the pixels within each province boundary. Doing it by hand is not preferable. I looked at the "color select" and just the plain old magic wand tool on GIMP to see, but it only gives me like the XY coordinates of the upper-left point of the selection. RE: Get all pixel coordinates of selection - Ofnuts - 09-28-2021 (09-28-2021, 12:17 PM)joho21 Wrote:(09-28-2021, 04:02 AM)PixLab Wrote:Quote:What I would like to know: is there an easy way to either get a list of all the XY coordinates of all pixels in a particular selection or, barring that, get the XY coordinates of all the pixels on a given layer? To do this you create a mask of each province before the game starts. To change the color of a province, you use the mask to make a selection, and then bucket fill the selection. Another method is to have each province in a separate alpha-locked layer, and then you just bucket-fill the layer with the new color. This technique is also quite easy to implement outside of Gimp with ImageMagick compose for instance. You can even have images of the the provinces in al the colors, and build the map by selecting the province images with the appropriate colors. RE: Get all pixel coordinates of selection - joho21 - 09-29-2021 (09-28-2021, 10:28 PM)Ofnuts Wrote:Okay... I've not used image manipulation code before, so I have no idea what any of that means. I'll certainly do some research into how to work with those things and see what I can come up with. It's a bit of a brand-new concept to me and I've heard it can be complicated to do image manipulation through just raw code. Thanks for the suggestions!(09-28-2021, 12:17 PM)joho21 Wrote:(09-28-2021, 04:02 AM)PixLab Wrote: I don't see where you want to go with "particular selection". You have multiple selection? RE: Get all pixel coordinates of selection - PixLab - 09-29-2021 (09-28-2021, 10:28 PM)Ofnuts Wrote: To do this you create a mask of each province before the game starts. To change the color of a province, you use the mask to make a selection, and then bucket fill the selection. As usual Ofnuts gives good advices I was thinking to have each province selection already saved in a channel, then the needed channel to selection > bucket-fill of that province selection (or just change the hue) In the end I prefer by far the the different Ofnuts's solutions, and a preference for the one which can be implemented in ImageMagicK, just to not depend about 1 software in case of a future bug in GIMP RE: Get all pixel coordinates of selection - joho21 - 09-29-2021 (09-29-2021, 06:24 AM)PixLab Wrote:(09-28-2021, 10:28 PM)Ofnuts Wrote: To do this you create a mask of each province before the game starts. To change the color of a province, you use the mask to make a selection, and then bucket fill the selection. Is there a way to do either suggestion within Python itself (the language I'm using)? I've looked at Gimp-Python, but it seems to only be for plugin stuff while I want to actually do it independently within the code. Most of the other suggestions I've looked at are also plugin-related stuff, especially with Python. There doesn't seem to be much in the way of editing the image without any user input. RE: Get all pixel coordinates of selection - Ofnuts - 09-29-2021 (09-29-2021, 02:43 PM)joho21 Wrote:(09-29-2021, 06:24 AM)PixLab Wrote:(09-28-2021, 10:28 PM)Ofnuts Wrote: To do this you create a mask of each province before the game starts. To change the color of a province, you use the mask to make a selection, and then bucket fill the selection. AFAIK ImageMagick has Python bindings so you can easily do all the image composition from Python. Otherwise Python has image handling libraries such a Pillow. |