Hello.
When using a PImage in alpha/greyscale format, how can I extract individual values from pixels? Should I use alpha(myImage.pixels[pos])? Or red(myImage.pixels[pos])?
Thank you in advance.
Hello.
When using a PImage in alpha/greyscale format, how can I extract individual values from pixels? Should I use alpha(myImage.pixels[pos])? Or red(myImage.pixels[pos])?
Thank you in advance.
Hi @amundsen,
From a low level system perspective I would say, depends on the implementation, but I would assume that processing internally keep PImage as independent from the several Image Implementations.
Means the grayscale is stored as R=G=B, but alpha can be different. So when you are interested in the alpha values you should use alpha, but if you are interested in the black to white shading, you can go for either red or green or blue …
Cheers
— mnse
PS: interesting question … I’ll check the proceesing source if I find tsome free time …
Please tell us when you have found the information!
The question is also in the other direction: which coding should one use to modify this PImage?
Hello @amundsen,
Lots of resources (tutorials, references and examples) here:
https://processing.org/
Explore these tutorials:
https://processing.org/tutorials/color
https://processing.org/tutorials/pixels
References:
https://processing.org/reference/#color
This is useful to understand color datatype:
A fun example I wrote to display the pixel color in hexadecimal notation at the mouse location:
PImage photo;
void setup()
{
size(200, 255);
// Image from https://en.wikipedia.org/wiki/Grayscale
photo = loadImage("https://upload.wikimedia.org/wikipedia/commons/f/fa/Grayscale_8bits_palette_sample_image.png");
println(photo.width, photo.height);
image(photo, 0, 0); // Display image
for (int i = 0; i< 256; i++)
{
stroke(i);
line(photo.width, i, width, i);
}
}
void draw()
{
if (mousePressed)
{
println(hex(get(mouseX, mouseY))); // See references!
}
}
I encourage you to start exploring the resources and experiment with writing some code to better understand these topics.
:)
Hi @amundsen,
check out the (as always) great resources to learn posted by @glv.
As promised, just had a quick look on the processing java source.
Basically there are 3 Modes (ARGB,RGB (also Grayscale),ALPHA/Greyscale) and as supposed in my first post …
Cheers
— mnse
PS: Source
Thanks a lot, @mnse !