Digital Images in Java Java’s imaging classes. Java imaging library  Java has good support for image processing  Must master a handful of classes and.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

Introduction to Java 2 Programming Lecture 10 API Review; Where Next.
Advanced Programming Issues JAI and Threads Courtesy ndanger at
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
Lecture 2 Concepts, Terms and Definitions. Display Devices They are divided into a lot of small squares called pixels (“PICture ELements”). Each pixel.
Chapter 11 Component-Level Design
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Digital Color 24-bit Color Indexed Color Image file compression
Lecture 9 Grey Level & Colour Enhancement TK3813 Dr. Masri Ayob.
The Binary Numbering Systems
Regional Processing There goes the neighborhood. Overview  Under point processing a single input sample is processed to produce a single output sample.
Digital Images in Java The structure of code and concept
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae & david streader, VUW Images and 2D Graphics COMP.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
Images and colour Colour - colours - colour spaces - colour models Raster data - image representations - single and multi-band (multi-channel) images -
First Bytes - LabVIEW. Today’s Session Introduction to LabVIEW Colors and computers Lab to create a color picker Lab to manipulate an image Visual ProgrammingImage.
Manipulating 2D arrays in Java
Chapter 2: Algorithm Discovery and Design
ImageJ Tutorial.
Trevor McCasland Arch Kelley.  Goal: reduce the size of stored files and data while retaining all necessary perceptual information  Used to create an.
Java: Chapter 1 Computer Systems Computer Programming II Aug
CSC – Java Programming II Lecture 9 January 30, 2002.
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
The NetBeans IDE CSIS 3701: Advanced Object Oriented Programming.
Welcome Topic: Pixels A.M.Meshkatur Rahman Class: vii Roll: 07.
Lab #5-6 Follow-Up: More Python; Images Images ● A signal (e.g. sound, temperature infrared sensor reading) is a single (one- dimensional) quantity that.
Java: Chapter 1 Computer Systems Computer Programming II.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Computer Science 101 Images in Web Pages. Image Files Two common formats, GIF and JPEG GIF images are more flexible for use as icons JPEG images are sharper.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Copyright © 2009 Curt Hill The Picture Object Getting and displaying.
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
7/11/20081 Today’s Agenda Friday 6 th Nov Revision of certain topics Floating point notation Excess Notation Exam format Interim Report.
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.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Two –Dimensional Arrays Mrs. C. Furman Java Programming November 19, 2008.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
Image Representation. Digital Cameras Scanned Film & Photographs Digitized TV Signals Computer Graphics Radar & Sonar Medical Imaging Devices (X-Ray,
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 18 產生驗證碼. No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
DIGITAL IMAGE. Basic Image Concepts An image is a spatial representation of an object An image can be thought of as a function with resulting values of.
Why a bitmap (.bmp), not a.jpg? If you cannot save a.bmp, make it an uncompressed.tif. Compression (of this 8-bit 397,000 pixel image): none (397kb memory)medium.
 By Bob “The Bird” Fiske & Anita “The Snail” Cost.
Image File Formats. What is an Image File Format? Image file formats are standard way of organizing and storing of image files. Image files are composed.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Image File Formats By Dr. Rajeev Srivastava 1. Image File Formats Header and Image data. A typical image file format contains two fields namely Dr. Rajeev.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Lecture 11 Text mode video
Java 2D Image Manipulation A Brief Overview Ziv Yaniv.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
Multidimensional Arrays
Representation of image data
Images and 2D Graphics COMP
Binary Representation in Audio and Images
Reading Netpbm Images.
Chapter 5 Working with Images
Representing Images 2.6 – Data Representation.
Multidimensional Arrays and Image Manipulation
COMS 161 Introduction to Computing
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Presentation transcript:

Digital Images in Java Java’s imaging classes

Java imaging library  Java has good support for image processing  Must master a handful of classes and methods for performing in- memory image processing operations.  These classes are given in the UML diagram below.  The BufferedImage  WritableRaster  BufferedImageOp are the central classes. 2

BufferedImage  The BufferedImage class  Defined in the java.awt.image package  Represents an image that is stored entirely in memory  Similar to the concept of the DigitaImage interface we presented earlier  Is flexible in terms of color model and the way in which samples are represented  Can always convert into RGB space even if the data is in another color space 3

BufferedImage methods  Note that the ‘getRGB’ takes a column and row (x,y) and returns the packed pixel. ‘setRGB’ is symmetric.  Also note that to create a BufferedImage, an image type must be specified.  The type designates the transfer type (byte, short, int)  The type also designates the color model  Some common types are predefined 4

How to create a BufferedImage  Consider making images with the BufferedImage constructor  The first expression creates an all-black 250 column by 300 row grayscale image where each sample is a byte  The second expression creates an all-black 400 column by 100 row color image where each sample is packed into an int  Note that the BufferedImage class doesn’t support methods that allow individual samples of a BufferedImage to be read or written! 5

ColorModel  The primary task of the ColorModel is to analyze a pixel and extract the individual color components  red, green, and blue, for example.  Also supports CMY, HSB or any other color model that you choose to develop  ColorModel is an abstract class with subclasses that support  packed pixel data (PackedColorModel)  indexed pixel data (IndexColorModel)  direct representation of samples (ComponentColorModel).  Since the RGB color space is the most common in general computing systems, RGB serves as a default. All ColorModels are able to convert from their native format to packed int RGB format. 6

java.awt.image.WritableRaster  Each BufferedImage contains a WritableRaster  Represents a two-dimensional array of pixels but is actually a one-dimensional array internally.  Similar to the LinearizedDigitalImage implementation.  A WritableRaster is the object that contains the actual sample data. (Actually the DataBuffer does, but that’s another story)  Sample data is read and written through the WritableRaster class. 7

javax.imageio.ImageIO  Often need to read a BufferedImage from a file or write a BufferedImage to a file  The ImageIO class provides static methods for reading and writing images  The ImageIO class supports PNG, JPEG, BMP and GIF formats.  It is important to understand that once the file is read and a BufferedImage constructed, there is no longer any connection between the BufferedImage and file.  While the BufferedImage that is created by the read method is an accurate depiction of the image file, there is no correlation between the representation of the BufferedImage and the file itself.  The file, for example, may use an indexed color model given in YCbCr color space while the BufferedImage may use a direct color model given in RGB space. 8

Example  Here is a code fragment that shows how the previous classes may be used to invert an image. The input image was created from a PNG file while the output image is saved as JPEG. 9

BufferedImageOp  The previous example is typical of single-source image processing operations  Single-source means that there is one image that is being processed  The operation creates a destination image  The source image is not modified but is used to create the destination  This process is represented in Java by the BufferedImageOp class 10

BufferedImageOp  The filter method accepts a BufferedImage source and destination.  If the destination is null, then a destination is created via the ‘createCompatibleDestImage’ method.  The source image is usually not modified  The other methods are often not used and will not be described in any detail.

Custom classes for code simplification  Consider the common pattern of iterating over the samples of an image using Java's library.  The three nested loops are  Lots of code to write  Error-prone since the  Nesting order can be important  Incorrect boundaries of the loops are easy to introduce via copy-and-paste  Order of the indices in the getSample method can be easily confused. 12

Custom classes for code simplification imaging.scanners.Location  This text uses some custom classes to simplify image processing patterns.  The Location class wraps the three indices of a sample (column, row, and band) into a single object.  Notice that the attributes are public 13

Custom classes for code simplification imaging.scanners.RasterScanner  A scanner is an iterator that traverses all of the Locations in an image in some well defined sequence.  The RasterScanner traverses the locations in top-to-bottom left-to-right fashion.  The source code of the RasterScanner is not presented but the scanner class is easy to use.  The code below replaces the three nested-loop pattern.  Should be understood as “for every sample s in image src, process s and place it into the destination”.  Note that the ‘true’ in the constructor indicates whether or not bands are to be included in the iteration. 14

Custom classes for code simplification imaging.ops.NullOp  Consider implementing the BufferedImageOp class  Must author a handful of methods  Lets write a very basic op that does nothing but “copy”  Call this operation the NullOp. Can then use this NullOp as a base class for many other ‘real’ operations.

Custom classes for code simplification imaging.ops.NullOp  Consider implementing the BufferedImageOp class  These methods must be provided but are often not used.  Note that the getBounds returns the bounding rectangle of the source image,  Note that getPoint2D maps a source location to a destination location (useful for geometric ops)  rendering hints may be effectively ignored.

Custom BufferedImageOp  The NullOp will now serve as a base class for most image processing operations presented in this text.  Subclasses will often need to include an overloaded ‘filter’ method and nothing else!  Consider taking the ‘inverse’ code presented earlier and refactoring the code as a NullOp subclass.

Using a BufferedImageOp  Using the BufferedImageOp  This code effectively replaces the code of listing

Displaying BufferedImages  Often want to see an image on the screen.  The imaging.gui.ImageComponent class can be used to display a BufferedImage  ImageComponent is a subclass of Component and so can be used in any Swing- based application 19