Introduction to Image processing using processing.

Slides:



Advertisements
Similar presentations
Playing with pixels Programming For Artists Learning objectives:
Advertisements

aims By the end of the session you will be able to: Explain how images are represented in Processing Manipulate images using the pixels member Use for.
Creative Computing. \\ aims By the end of the session you will be able to: 1.Explain the difference between various image file formats 2.Load in and display.
Md. Monjur –ul-Hasan Department of Computer Science & Engineering Chittagong University of Engineering & Technology Chittagong 4349
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
Introduction to Programming
Chapter Eleven Digital Darkroom Expert Techniques.
Computer Science 111 Fundamentals of Programming I More Digital Image Processing.
Review Images – an array of colors Color – RGBA Loading, modifying, updating pixels pixels[] as a 2D array Simple filters – tinting, grayscale, negative,
Computational Biology, Part 23 Biological Imaging II Robert F. Murphy Copyright  1996, 1999, All rights reserved.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
DIGITAL IMAGE PROCESSING CMSC 150: Lecture 14. Conventional Cameras  Entirely chemical and mechanical processes  Film: records a chemical record of.
Graphics File Formats. 2 Graphics Data n Vector data –Lines –Polygons –Curves n Bitmap data –Array of pixels –Numerical values corresponding to gray-
Fundamentals of Python: From First Programs Through Data Structures
Images and colour Colour - colours - colour spaces - colour models Raster data - image representations - single and multi-band (multi-channel) images -
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Video in Processing David Meredith Aalborg University.
GIMP Graphic Image Manipulation Program. GIMP Image manipulation software Free Open Source Written by two students First version in 1996.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
L. Akshay Masare Piyush Awasthi IMAGE PROCESSING AND OPENCV.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Introduction to Processing CS 4390/5390 Fall 2014 Shirley Moore, Instructor September 3,
AdeptSight Image Processing Tools Lee Haney January 21, 2010.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Image Representation. Digital Cameras Scanned Film & Photographs Digitized TV Signals Computer Graphics Radar & Sonar Medical Imaging Devices (X-Ray,
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Processing can load images, display them on the screen, and change their size, position, opacity, and tint. You can load gif, png and jpg images in processing.
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
How digital cameras work The Exposure The big difference between traditional film cameras and digital cameras is how they capture the image. Instead of.
Images. Digital Images Rectangular arrays of pixel data Pixel - picture element, smallest addressable part of the frame buffer. Color depth - the depth.
Digital Imaging Fundamentals Ms. Hema C.R. School of Mechatronic Engineering.
Animation Pages Function Function Definition Calling a function Parameters Return type and return statement.
Scanning Basics. An image can be created, opened, edited, and saved in over a dozen different file formats in Photoshop. Of these, you might use only.
TOPIC 10 THE IF STATEMENT 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Visual Computing Computer Vision 2 INFO410 & INFO350 S2 2015
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Digital & Interactive Media
Graphics III Image Processing II.
Intelligent Robotics Today: Vision & Time & Space Complexity.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
PART TWO Electronic Color & RGB values 1. Electronic Color Computer Monitors: Use light in 3 colors to create images on the screen Monitors use RED, GREEN,
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
Scanner Scanner Introduction: Scanner is an input device. It reads the graphical images or line art or text from the source and converts.
Lecture 11 Text mode video
An Introduction to Digital Image Processing Dr.Amnach Khawne Department of Computer Engineering, KMITL.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
數位影像處理 Digital Image Processing 吳育龍老師. Read image data Screen Resolution : 1024 X
Image Processing Objectives To understand pixel based image processing
David Meredith Aalborg University
Binary Representation in Audio and Images
Kyoungju Park Computer Graphics Kyoungju Park
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Basic Graphics Drawing Shapes 1.
Fundamentals of Programming I Introduction to Digital Image Processing
Chapter 15, Images …a few points
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Chapter 15, Images …a few points
Presentation transcript:

Introduction to Image processing using processing

2 Image processing The analysis, manipulation, storage, and display of graphical images from sources such as photographs, drawings, and video.

3 Three steps in image processing Image processing spans a sequence of three steps. –The input step (image capture and digitizing) converts the differences in coloring and shading in the picture into binary values that a computer can process. –The processing step can include image enhancement and data compression. –The output step consists of the display or printing of the processed image. Image processing is used in such applications as television and film, medicine, satellite weather mapping, machine vision, and computer based pattern recognition.

4 The PIXEL array and LOCATION calculation We can get at the pixels of the display window, using the array “pixels". Each pixel on the screen has an X,Y coordinate However, the array "pixels" in a one-dimensional array We need a way to access one dimensional array with X, Y coordinate 1. Assume a window or image with a given WIDTH and HEIGHT. 2. We then know the pixel array has a total number of elements equaling WIDTH * HEIGHT. 3. For any given point in the windows (X,Y), the location in our 1 dimensional pixel array is: –LOCATION = X + Y*WIDTH

5 loadPixels() –Loads the pixel data for the display window into the pixels[] array. This function must always be called before reading from or writing to pixels[]. updatePixels() –Updates the display window with the data in the pixels[] array. Use in conjunction with loadPixels().

6 Example(Generate Random Image) size(50,50); loadPixels(); //nested loop to walk through every x and y coordinate //like with our 2D array for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { //pick a random number, 0 to 255 int rand = int(random(255)); //create a grayscale color based on random number color c = color(rand,rand,rand); //do our location calculation int loc = x + y*width; //set pixel at that location to random color pixels[loc] = c; } updatePixels(); }

7 Example(Show loaded image) PImage a; void setup() { size(200, 200); a = loadImage("jelly.jpg"); noLoop(); } void draw() { loadPixels(); background(0); for (int x = 0; x < a.width; x++) { for (int y = 0; y < a.height; y++ ) { //calculate the 1D location from a 2D grid int loc = x + y*a.width; //get the R,G,B values from image float r,g,b; r = red (a.pixels[loc]); g = green (a.pixels[loc]); b = blue (a.pixels[loc]); //****DO OUR IMAGE PROCESSING STUFF HERE*******/ //make a new color and set pixel in the window color c = color(r,g,b); pixels[loc] = c; } updatePixels(); }

8 Example(Change brightness) PImage a; void setup() { size(200, 200); a = loadImage("jelly.jpg"); } void draw() { loadPixels(); background(255); for (int x = 0; x < a.width; x++) { for (int y = 0; y < a.height; y++ ) { //calculate the 1D location from a 2D grid int loc = x + y*a.width; //get the R,G,B values from image float r,g,b; r = red (a.pixels[loc]); g = green (a.pixels[loc]); b = blue (a.pixels[loc]); //do some sort of calculation to the RGB values (increase brightness according to the mouse here) r += ((float) mouseX / width) * 255; g += ((float) mouseX / width) * 255; b += ((float) mouseX / width) * 255; //constrain RGB to make sure they are within color range r = constrain(r,0,255); g = constrain(g,0,255); b = constrain(b,0,255); //make a new color and set pixel in the window color c = color(r,g,b); pixels[loc] = c; } updatePixels(); }

9 Example(Thresholding) PImage a; void setup() { size(200, 200); a = loadImage("jelly.jpg"); } void draw() { loadPixels(); background(255); for (int x = 0; x < a.width; x++) { for (int y = 0; y < a.height; y++ ) { //calculate the 1D location from a 2D grid int loc = x + y*a.width; //get the R,G,B values from image float r,g,b; r = red (a.pixels[loc]); g = green (a.pixels[loc]); b = blue (a.pixels[loc]); //calculate a threshold from based on mouseX int threshold = int(((float) mouseX / width) * 255); color c; //do a threshold test based on brightness if (brightness(a.pixels[loc]) > threshold) { c = color(255,255,255); } else { c = color(0,0,0); } pixels[loc] = c; // color c = color(r,g,b); // pixels[loc] = c; } updatePixels(); }

10 Spatial convolution This process uses a weighted average of an input pixel and its neighbors to calculate an output pixel value. We can use neighboring groups of different sizes, such as 3x3, 5x5, etc. Different combinations of different weights for each pixel can result in different effects Sharpen: Blur: 1/9 1/9 1/9 new_pixelvalue(i,j) = old_pixelvalue(i-1, j-1)*(-1) + old_pixelvalue(i-1, j)*(-1) + old_pixelvalue(i-1, j+1)*(-1) + old_pixelvalue(i, j-1)*(-1) + old_pixelvalue(i, j)*(9) + old_pixelvalue(i, j+1)*(-1) + old_pixelvalue(i+1, j-1)*(-1) + old_pixelvalue(i+1, j)*(-1) + old_pixelvalue(i+1, j+1)*(-1)

11 Example(Sharpening) color Convolve(int x, int y, float[] Matrix, PImage a) { float sumR = 0.0; float sumG = 0.0; float sumB = 0.0; //is our matrix 3x3, 5x5, etc.? int MatrixSize = int(sqrt(Matrix.length)); //to keep track of where we are in convolution matrix int countMatrix = 0; for (int i =-MatrixSize/2; i <= MatrixSize/2; i++){ for (int j=-MatrixSize/2; j <= MatrixSize/2; j++){ //what pixel are we testing int xloc = x+i; int yloc = y+j; int loc = xloc + a.width*(yloc+j); //make sure we haven not walked off our image loc = constrain(loc,0,a.pixels.length-1); //calculate the convolution sumB += (blue(a.pixels[loc]) * Matrix[countMatrix]); sumG += (green(a.pixels[loc]) * Matrix[countMatrix]); sumR += (red(a.pixels[loc]) * Matrix[countMatrix]); countMatrix++; } //make sure RGB is withing range sumR = constrain(sumR,0,255); sumG = constrain(sumG,0,255); sumB = constrain(sumB,0,255); //return the resulting color return color(sumR,sumG,sumB); } PImage a; void setup() { size(400, 400); a = loadImage("penguin.jpg"); } void draw() { //we're only going to process a portion of the image so let's set the whole image as the background first image(a,0,0); loadPixels(); //For drawing a black rectangle defining area for processing stroke(0); noFill(); rectMode(CENTER_DIAMETER); rect(mouseX,mouseY,81,81); //what are the boundaries for the pixels we are processing int X1 = constrain(mouseX-40,0,a.width); int Y1 = constrain(mouseY-40,0,a.height); int X2 = constrain(mouseX+40,0,a.width); int Y2 = constrain(mouseY+40,0,a.height); //begin our loop for every pixel for (int x = X1; x < X2; x++) { for (int y = Y1; y < Y2; y++ ) { float[] Matrix= { -1,-1,-1, -1, 9,-1, -1,-1,-1 }; color c = Convolve(x,y,Matrix,a); int loc = x + y*a.width; pixels[loc] = c; } updatePixels(); }

12 Example (blurring) color Convolve(int x, int y, float[] Matrix, PImage a) { float sumR = 0.0; float sumG = 0.0; float sumB = 0.0; //is our matrix 3x3, 5x5, etc.? int MatrixSize = int(sqrt(Matrix.length)); //to keep track of where we are in convolution matrix int countMatrix = 0; for (int i =-MatrixSize/2; i <= MatrixSize/2; i++){ for (int j=-MatrixSize/2; j <= MatrixSize/2; j++){ //what pixel are we testing int xloc = x+i; int yloc = y+j; int loc = xloc + a.width*(yloc+j); //make sure we haven not walked off our image loc = constrain(loc,0,a.pixels.length-1); //calculate the convolution sumB += (blue(a.pixels[loc]) * Matrix[countMatrix]); sumG += (green(a.pixels[loc]) * Matrix[countMatrix]); sumR += (red(a.pixels[loc]) * Matrix[countMatrix]); countMatrix++; } //make sure RGB is withing range sumR = constrain(sumR,0,255); sumG = constrain(sumG,0,255); sumB = constrain(sumB,0,255); //return the resulting color return color(sumR,sumG,sumB); } PImage a; void setup() { size(400, 400); a = loadImage("penguin.jpg"); } void draw() { //we're only going to process a portion of the image so let's set the whole image as the background first image(a,0,0); loadPixels(); //For drawing a black rectangle defining area for processing stroke(0); noFill(); rectMode(CENTER_DIAMETER); rect(mouseX,mouseY,81,81); //what are the boundaries for the pixels we are processing int X1 = constrain(mouseX-40,0,a.width); int Y1 = constrain(mouseY-40,0,a.height); int X2 = constrain(mouseX+40,0,a.width); int Y2 = constrain(mouseY+40,0,a.height); //begin our loop for every pixel for (int x = X1; x < X2; x++) { for (int y = Y1; y < Y2; y++ ) { float[] Matrix = new float[25]; for (int i = 0; i < 25; i++) { Matrix[i] = 1.0f/25.0f;; } color c = Convolve(x,y,Matrix,a); int loc = x + y*a.width; pixels[loc] = c; } updatePixels(); }

13 Example (edge detection) color Convolve(int x, int y, float[] Matrix, PImage a) { float sumR = 0.0; float sumG = 0.0; float sumB = 0.0; //is our matrix 3x3, 5x5, etc.? int MatrixSize = int(sqrt(Matrix.length)); //to keep track of where we are in convolution matrix int countMatrix = 0; for (int i =-MatrixSize/2; i <= MatrixSize/2; i++){ for (int j=-MatrixSize/2; j <= MatrixSize/2; j++){ //what pixel are we testing int xloc = x+i; int yloc = y+j; int loc = xloc + a.width*(yloc+j); //make sure we haven not walked off our image loc = constrain(loc,0,a.pixels.length-1); //calculate the convolution sumB += (blue(a.pixels[loc]) * Matrix[countMatrix]); sumG += (green(a.pixels[loc]) * Matrix[countMatrix]); sumR += (red(a.pixels[loc]) * Matrix[countMatrix]); countMatrix++; } //make sure RGB is withing range sumR = constrain(sumR,0,255); sumG = constrain(sumG,0,255); sumB = constrain(sumB,0,255); //return the resulting color return color(sumR,sumG,sumB); } PImage a; void setup() { size(400, 400); a = loadImage("penguin.jpg"); } void draw() { //we're only going to process a portion of the image so let's set the whole image as the background first image(a,0,0); loadPixels(); //For drawing a black rectangle defining area for processing stroke(0); noFill(); rectMode(CENTER_DIAMETER); rect(mouseX,mouseY,81,81); //what are the boundaries for the pixels we are processing int X1 = constrain(mouseX-40,0,a.width); int Y1 = constrain(mouseY-40,0,a.height); int X2 = constrain(mouseX+40,0,a.width); int Y2 = constrain(mouseY+40,0,a.height); //begin our loop for every pixel for (int x = X1; x < X2; x++) { for (int y = Y1; y < Y2; y++ ) { float[] Matrix = {-1, 0, 1, -2, 0, 2, -1, 0, 1}; float[] Matrix1= {1, 2, 1, 0, 0, 0, -1, -2, -1}; color c = Convolve(x,y,Matrix,a); color c2 = Convolve(x, y, Matrix1, a); int loc = x + y*a.width; // pixels[loc] = constrain(c+c2, 0, 255); pixels[loc]=color(brightness(c2+c)); color c = Convolve(x,y,Matrix,a); int loc = x + y*a.width; pixels[loc] = c; } updatePixels(); }

14 Assignment Implement a program which do sharpening, blurring, edge detection on an image. Switch among sharpening, blurring, edge detection mode on mouse button click

15 Video capture import processing.video.*; Capture cam; void setup() { size(640, 480); // If no device is specified, will just use the default. cam = new Capture(this, 640, 480); } void draw() { if (cam.available() == true) { cam.read(); image(cam, 0, 0); } To run this program we need install Quicktime 7.0 and WinVDIG

16 Play video import processing.video.*; Movie myMovie; void setup() { size(640, 480, P2D); background(0); // Load and play the video in a loop myMovie = new Movie(this, "station.mov"); myMovie.loop(); } void movieEvent(Movie myMovie) { myMovie.read(); } void draw() { tint(255, 20); image(myMovie, mouseX- myMovie.width/2, mouseY- myMovie.height/2); filter(GRAY); }

17 tint() Sets the fill value for displaying images. Images can be tinted to specified colors or made transparent by setting the alpha. To make an image transparent, but not change it's color, use white as the tint color and specify an alpha value. For instance, tint(255, 128) will make an image 50% transparent

18 filter() Filters the display window as defined by one of the following modes: THRESHOLD - converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. GRAY - converts any colors in the image to grayscale equivalents INVERT - sets each pixel to its inverse value POSTERIZE - limits each channel of the image to the number of colors specified as the level parameter BLUR - executes a Guassian blur with the level parameter specifying the extent of the blurring. OPAQUE - sets the alpha channel to entirely opaque. ERODE - reduces the light areas with the amount defined by the level parameter. DILATE - increases the light areas with the amount defined by the level parameter

19 Assignment Implement a program which various filtering on an video. Switch among THRESHOLD, GRAY, INVERT, POSTERIZE, BLUR, OPAQUE, ERODE, DILATE filtering mode on mouse button click