I'm dabbling into artificial intelligence more And more and many techniques is to 'scan ' an image and store pixel information into a 2D table then feed that table into a neural network.
If I draw/ display a graphic on the screen with Love 2D, how might I get RGB values for the pixel at coordinates (50, 50)?
Assume a random image was loaded and displayed with love.graphucs draw()
how to test the colour of a pixel?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
how to test the colour of a pixel?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: how to test the colour of a pixel?
Ironic that you're asking this when in a neighbouring thread someone is asking about love.graphics.captureScreenshot
ImageData is the type you need if you want to read pixels.
ImageData is the type you need if you want to read pixels.
Re: how to test the colour of a pixel?
togFox wrote: ↑Wed Mar 01, 2023 9:42 pm I'm dabbling into artificial intelligence more And more and many techniques is to 'scan ' an image and store pixel information into a 2D table then feed that table into a neural network.
If I draw/ display a graphic on the screen with Love 2D, how might I get RGB values for the pixel at coordinates (50, 50)?
Assume a random image was loaded and displayed with love.graphucs draw()
Code: Select all
mask = love.image.newImageData('assets/images/example.png')
local r, g, b, a = mask:getPixel(x, y)
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
- BrotSagtMist
- Party member
- Posts: 665
- Joined: Fri Aug 06, 2021 10:30 pm
Re: how to test the colour of a pixel?
love.graphics.captureScreenshot( callback ) will turn your screen into image data passed to callback.
Your callback should then use https://love2d.org/wiki/ImageData:mapPixel to get the pixel values.
Callback can be a thread stack meaning that you can deciper the data on another thread while the game is running, thats so far the smartest solution.
Your callback should then use https://love2d.org/wiki/ImageData:mapPixel to get the pixel values.
Callback can be a thread stack meaning that you can deciper the data on another thread while the game is running, thats so far the smartest solution.
obey
Re: how to test the colour of a pixel?
Oh - that simple? I was expecting a far more complicated response!
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: how to test the colour of a pixel?
Well, if you do want to draw it out first, and then read the image back with captureScreenshot, for whatever convoluted reason, that will have a gigantic delay due to the data going this way: RAM -> VRAM -> RAM.
If you can just use ImageData and manipulate that, you save yourself that hassle.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: how to test the colour of a pixel?
Yeah - performance is something I'll need to check and ensure I don't scan too many pixels too quickly
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Re: how to test the colour of a pixel?
An alternative to capturing a screenshot is using a render target, AKA the Canvas object.
Check the samples for how to use it, including its newImageData() function, comparable to captureScreenshot().
Check the samples for how to use it, including its newImageData() function, comparable to captureScreenshot().
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 7 guests