#Help with isolating pixel colour to only its brightest channel
11 messages · Page 1 of 1 (latest)
Hey, so what you need to do to change all pixels in an image is to have have two for each loops. One for all pixels in x. One for all pixels in y. If you nest this, it can access all pixels . From their, I believe you would use something like a buffered image / reader to make the conversion.
Do you mind providing me with pseudo code? I'm having trouble conceptualizing it
Here is a stack overflow post on it https://stackoverflow.com/questions/27071351/change-the-color-of-each-pixel-in-an-image-java
but yeah, this is kinda what I was refering to ```java
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
image.setRGB(i, j, 0);
}
}
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}```
Thats not really what I need rn, I want to darken this image into the second image.
import Media.*;
import java.awt.Color;
public class Vivid {
private PictureDisplayer display; // Declaring PictureDisplayer
/*
* Constructor for objects of class Vivid
*/
public Vivid() {
Picture picture = new Picture(); // Instantiating picture
display = new PictureDisplayer(picture); // Instantiating display and placing picture
display.waitForUser(); // Shows altered image after waiting for user
changeImage(picture); // Displays altered image
display.close();
}
/*
* Changes image to just red, green and blue
*/
private void changeImage(Picture picPassed){
Pixel p;
// Traverses through image pixels
while (picPassed.hasNext()) {
p = picPassed.next();
int g = p.getGreen();
int b = p.getBlue();
int r = p.getRed();
// If red is greater than green and blue, set pixel red
if (r > g && r > b) {
p.setColor(Color.RED);
}
// If green is greater than red and blue, set pixel green
if (g > r && g > b){
p.setColor(Color.GREEN);
}
// If blue is greater than red and green, set pixel blue
if (b > r && b > g){
p.setColor(Color.BLUE);
}
}
}
}
but for some reason my code just isnt working
idk why that is
I guess what I want to go for is a slight transparent effect showing green over the trees, blue over the sky and ocean, and red over the sand but I have no clue on how to create this transparency
I want to turn this image into the red green and blue image