Posts: 4
Threads: 1
Joined: Sep 2021
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
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?
Posts: 1,528
Threads: 70
Joined: May 2021
Reputation:
167
Operating system(s):
Gimp version: 2.10
09-28-2021, 04:02 AM
(This post was last modified: 09-28-2021, 04:27 AM by PixLab.)
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)
Posts: 6,361
Threads: 275
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(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?
Posts: 4
Threads: 1
Joined: Sep 2021
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
(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?
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)
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.
Posts: 6,361
Threads: 275
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(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?
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)
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.
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.
Posts: 4
Threads: 1
Joined: Sep 2021
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
(09-28-2021, 10:28 PM)Ofnuts Wrote: (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?
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)
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.
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.
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!
Posts: 1,528
Threads: 70
Joined: May 2021
Reputation:
167
Operating system(s):
Gimp version: 2.10
09-29-2021, 06:24 AM
(This post was last modified: 09-29-2021, 07:10 AM by PixLab.)
(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.
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.
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
Posts: 4
Threads: 1
Joined: Sep 2021
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
Gimp version: 2.10
09-29-2021, 02:43 PM
(This post was last modified: 09-29-2021, 03:41 PM by joho21.)
(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.
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.
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
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.
Posts: 6,361
Threads: 275
Joined: Oct 2016
Reputation:
565
Operating system(s):
Gimp version: 2.10
(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.
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.
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
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.
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.
|