Image Pixel Value
in
Programming Questions
•
2 years ago
Hey Processors
I have been working on a small problem of changing the values of pixels to "red" (or any color other than black or white).
I modify the pixel itself and its six neighbors. As per the changes the pixel values must be changed to "red". But when I run another loop over the image to verify the changes, out of 7 pixels only 3 or sometimes 4 come up as red. Upon further analysis I found out that the pixel values are some shade of red.
How can I make sure that when I set the value of the pixel it is color(255,0,0) and not a shade?
Ciao!
- img1.loadPixels();
- int loc = pixelX + pixelY*img2.width;
- img1.pixels[loc] = color(255,0,0);
- loc = pixelX + (pixelY +1)*img2.width;
- img1.pixels[loc] = color(255,0,0);
- loc = (pixelX+1) + (pixelY+1)*img2.width;
- img1.pixels[loc] = color(255,0,0);
- loc = pixelX + (pixelY-1)*img2.width;
- img1.pixels[loc] = color(255,0,0);
- loc = (pixelX+1) + (pixelY-1)*img2.width;
- img1.pixels[loc] = color(255,0,0);
- loc = (pixelX+1) + (pixelY)*img2.width;
- img1.pixels[loc] = color(255,0,0);
- loc = (pixelX-1) + (pixelY)*img2.width;
- img1.pixels[loc] = color(255,0,0);
- img1.updatePixels();
- img1.save("modifiedImage.jpg");
- img1.loadpixels();
- for (int i=2; i < img1.width; i++)
- {
- for (int j=2; j < img1.height; j++)
- {
- loc = i + (2*j)*img1.width;
- if (img1.pixels[i + (2*j)*img1.width] == color(255,0,0))
- {
- println("Pixels " + i + ":" +2*j);
- }
- }
- }
1