PImage sample; void setup() { size(300,300); sample = loadImage("sample.jpg"); sample.loadPixels(); image(sample,0,0,300,300); } void draw() { //Loop to scan the image pixel by pixel for (int x=0; x < sample.width; x++){ for (int y=0; y < sample.height; y++){ int location = x + (y * sample.width); // Whit the location you can get the current color color currentColor = sample.pixels[loc]; //Do something } } }
public static void createAnaglyph(PImage imgL, PImage imgR, PImage imgOut) { imgL.loadPixels(); imgR.loadPixels(); imgOut.loadPixels(); int[] pL = imgL.pixels; int[] pR = imgR.pixels; int[] pO = imgOut.pixels; for (int i = 0; i < pL.length; i++) { pO[i] = (pR[i] >> 16) << 16 | (pL[i] >> 8) & 255 << 8 | pL[i] & 255; // pO[i] = pL[i]; } imgOut.updatePixels(); // imgL.updatePixels(); }
int scaledWidth = (int)(sf*o.width); int scaledHeight = (int)(sf*o.height); PImage out = createImage(scaledWidth, scaledHeight, RGB); o.loadPixels(); out.loadPixels(); for (int i = 0; i < scaledHeight; i++) { for (int j = 0; j < scaledWidth; j++) { int y = Math.min( round(i / sf), o.height ) * o.width; int x = Math.min( round(j / sf), o.width ); out.pixels[(int)((scaledWidth * i) + j)] = o.pixels[(y + x)]; } }
/** * Returns a native BufferedImage from this PImage. */ public Object getNative() { // ignore loadPixels(); int type = (format == RGB) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage image = new BufferedImage(pixelWidth, pixelHeight, type); WritableRaster wr = image.getRaster(); wr.setDataElements(0, 0, pixelWidth, pixelHeight, pixels); return image; }
PImage img; void setup () { colorMode(HSB, 100); img = loadImage ("img.png"); size(img.width,img.height); color sat = color (0,0,0); img.loadPixels(); for (int i = 0; i < width * height; i++) { img.pixels[i]=color (hue(img.pixels[i]), sat, brightness(img.pixels[i])); } img.updatePixels(); image(img,0,0); }
PImage img; void setup() { // this is run once. size(600, 400); img=loadImage("http://c.tadst.com/gfx/600x400/int-mountain-day.jpg?1"); img.loadPixels(); int dimension = (img.width*img.height); for (int i=0; i < dimension; i+=2) { img.pixels[i] = color(0, 0, 0); } img.updatePixels(); } void draw() { // this is run repeatedly. It only draws the image again and again. image(img, 0, 0); }
/** * @param maskArray array of integers used as the alpha channel, needs to be * the same length as the image's pixel array. */ public void mask(int maskArray[]) { // ignore loadPixels(); // don't execute if mask image is different size if (maskArray.length != pixels.length) { throw new IllegalArgumentException("mask() can only be used with an image that's the same size."); } for (int i = 0; i < pixels.length; i++) { pixels[i] = ((maskArray[i] & 0xff) << 24) | (pixels[i] & 0xffffff); } format = ARGB; updatePixels(); }
return; out.loadPixels(); avgRed = 0; avgGreen = 0;
/** * Set alpha channel for an image. Black colors in the source * image will make the destination image completely transparent, * and white will make things fully opaque. Gray values will * be in-between steps. * <P> * Strictly speaking the "blue" value from the source image is * used as the alpha color. For a fully grayscale image, this * is correct, but for a color image it's not 100% accurate. * For a more accurate conversion, first use filter(GRAY) * which will make the image into a "correct" grayscake by * performing a proper luminance-based conversion. */ public void mask(int alpha[]) { loadPixels(); // don't execute if mask image is different size if (alpha.length != pixels.length) { throw new RuntimeException("The PImage used with mask() must be " + "the same size as the applet."); } for (int i = 0; i < pixels.length; i++) { pixels[i] = ((alpha[i] & 0xff) << 24) | (pixels[i] & 0xffffff); } format = ARGB; updatePixels(); }
img.loadPixels(); mask(img.pixels);
sceneMap = new int[numPixels];//init scene nap array scene.loadPixels(); bg = color(0);
/** * Set alpha channel for an image using another image as the source. */ public void mask(PImage alpha) { if (alpha.pixels == null) { // if pixels haven't been loaded by the user, then only load them // temporarily to save memory when finished. alpha.loadPixels(); mask(alpha.pixels); alpha.pixels = null; } else { mask(alpha.pixels); } }
import dLibs.freenect.toolbox.*; import dLibs.freenect.constants.*; import dLibs.freenect.interfaces.*; import dLibs.freenect.*; Kinect kinect; // main kinect-object KinectFrameDepth kinectDepth; // depth frame PImage depthFrame; void setup(){ size(640,480); kinect = new Kinect(0); kinectDepth = new KinectFrameDepth(DEPTH_FORMAT._11BIT_);// create a depth instance kinectDepth.connect(kinect); //connect the created depth instance to the main kinect depthFrame = createImage(DEPTH_FORMAT._11BIT_.getWidth(), DEPTH_FORMAT._11BIT_.getHeight(), RGB); } void draw(){ assignPixels(depthFrame, kinectDepth); image(depthFrame, 0, 0); } void assignPixels(PImage img, Pixelable kinectDev){ img.loadPixels(); img.pixels = kinectDev.getPixels(); // assign pixels of the kinect device to the image img.updatePixels(); } void dispose(){ Kinect.shutDown(); super.dispose(); }
@Override protected void setImpl(PImage sourceImage, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int targetX, int targetY) { sourceImage.loadPixels(); int sourceOffset = sourceX + sourceImage.pixelWidth * sourceY; PixelWriter pw = context.getPixelWriter(); pw.setPixels(targetX, targetY, sourceWidth, sourceHeight, argbFormat, sourceImage.pixels, sourceOffset, sourceImage.pixelWidth); // Let's keep them loaded if (loaded) { int sourceStride = sourceImage.pixelWidth; int targetStride = pixelWidth; int targetOffset = targetX + targetY * targetStride; for (int i = 0; i < sourceHeight; i++) { System.arraycopy(sourceImage.pixels, sourceOffset + i * sourceStride, pixels, targetOffset + i * targetStride, sourceWidth); } } }
int targetX, int targetY) { if (sourceImage.pixels == null) { sourceImage.loadPixels();
/** * Get the occurences of a given color, given a error. * * @param c color to find. * @param threshold error margin * @return number of occurences. */ public int computeOccurencesOfColor(int c, int threshold) { // TODO: Hack for noCamera, better to be done. if (paperScreen.cameraTracking == null) { return 0; } PImage out = getImage(); if (out == null) { return 0; } out.loadPixels(); int pxNb = picWidth * picHeight; int nbSameColor = 0; for (int k = 0; k < pxNb; k++) { int c2 = out.pixels[k]; boolean isClose = MathUtils.colorDistRGB(c, c2, threshold); if (isClose) { nbSameColor++; } } return nbSameColor; }
/** * * Deprecated */ // static public void PImageToIplImage(PImage src, IplImage dst) { // dst.copyFrom((BufferedImage) src.getImage()); // } public static void PImageToIplImage2(opencv_core.IplImage img, boolean RGB, PImage ret) { ByteBuffer buff = img.getByteBuffer(); ret.loadPixels(); if (RGB) { for (int i = 0; i < img.width() * img.height(); i++) { int offset = i * 3; ret.pixels[i] = (buff.get(offset) & 255) << 16 | (buff.get(offset + 1) & 255) << 8 | (buff.get(offset + 2) & 255); } } else { for (int i = 0; i < img.width() * img.height(); i++) { int offset = i * 3; ret.pixels[i] = (buff.get(offset + 2) & 255) << 16 | (buff.get(offset + 1) & 255) << 8 | (buff.get(offset) & 255); } } ret.updatePixels(); }
protected Object initCache(PImage img) { if (!checkGLThread()) { return null; } Texture tex = (Texture)getCache(img); if (tex == null || tex.contextIsOutdated()) { tex = addTexture(img); if (tex != null) { img.loadPixels(); tex.set(img.pixels, img.format); img.setModified(); } } return tex; }
protected Object initCache(PImage img) { if (!checkGLThread()) { return null; } Texture tex = (Texture)getCache(img); if (tex == null || tex.contextIsOutdated()) { tex = addTexture(img); if (tex != null) { img.loadPixels(); tex.set(img.pixels, img.format); img.setModified(); } } return tex; }
/** * Simple visualization * * @param depth * @param color * @param skip * @return */ public PImage update(IplImage depth, IplImage color, int skip) { updateRawDepth(depth); if (color != null) { updateRawColor(color); } depthData.clear(); depthData.timeStamp = papplet.millis(); validPointsPImage.loadPixels(); // set a default color. Arrays.fill(validPointsPImage.pixels, papplet.color(0, 0, 0)); // TODO: get the color with Kinect2... if (this.colorCamera.getPixelFormat() == Camera.PixelFormat.RGB) { computeDepthAndDo(skip, new SetImageDataRGB()); } if (this.colorCamera.getPixelFormat() == Camera.PixelFormat.BGR) { computeDepthAndDo(skip, new SetImageData()); } validPointsPImage.updatePixels(); return validPointsPImage; }