CS 335 Graphics and Multimedia. Image Manipulation

Similar documents
Graphical User Interfaces 2

Graphical User Interfaces 2

H212 Introduction to Software Systems Honors

Graphic User Interfaces. - GUI concepts - Swing - AWT

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

First Name: AITI 2004: Exam 2 July 19, 2004

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

CSIS 10A Assignment 14 SOLUTIONS

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

1005ICT Object Oriented Programming Lecture Notes

Graphical User Interfaces 2

Chapter 13 Lab Advanced GUI Applications

First Name: AITI 2004: Exam 2 July 19, 2004

Lecture 3: Java Graphics & Events

Client-side GUI. A simple Swing-gui for searching for proudcts

Building Graphical User Interfaces. GUI Principles

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

User interfaces and Swing

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Advanced Java Unit 6: Review of Graphics and Events

Lecture 5: Java Graphics

CIS 120 Programming Languages and Techniques. Final Exam, May 3, 2011

AP CS Unit 12: Drawing and Mouse Events

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

CS 106A, Lecture 14 Events and Instance Variables

Handling Mouse and Keyboard Events

II 12, JFileChooser. , 2. SolidEllipse ( 2), PolyLine.java ( 3). Draw.java

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

AP CS Unit 11: Graphics and Events

AP Computer Science Unit 13. Still More Graphics and Animation.

Swing from A to Z Some Simple Components. Preface

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Image Java Foundation Classes (JFC) java.awt.image JFC. Image. Image. Image PNG GIF JPEG

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

MIT AITI Swing Event Model Lecture 17

CIS 162 Project 1 Business Card Section 04 (Kurmas)

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Computer Science 210: Data Structures. Intro to Java Graphics

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

State Application Using MVC

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 2

Final Examination Semester 2 / Year 2012

More Swing. CS180 Recitation 12/(04,05)/08

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Window Interfaces Using Swing Objects

Java Coordinate System

Building Graphical User Interfaces. Overview

BM214E Object Oriented Programming Lecture 13

Systems Programming Graphical User Interfaces

// autor igre Ivan Programerska sekcija package mine;

CS 106A, Lecture 14 Events and Instance Variables

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

FirstSwingFrame.java Page 1 of 1

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Window Interfaces Using Swing Objects

SWING - GROUPLAYOUT CLASS

Chapter 1 GUI Applications

CMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

!"# $ %&# %####' #&() % # # # #&* # ## +, # -

Swing from A to Z Using Focus in Swing, Part 2. Preface

Introduction to Digital Image Processing

SAMPLE EXAM Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

protected void printserial() { System.out.println("> NO." + this.serialno); this.serialno++; }

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

javax.swing Swing Timer

Java Help Files. by Peter Lavin. May 22, 2004

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Unit 7: Event driven programming

Example: not good design. Motivation for MVC. public class BankAccount extends JPanel implements ActionListener

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Using Several Components

Chapter 14: Applets and More

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

(Incomplete) History of GUIs

A sample print out is: is is -11 key entered was: w

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Class 27: Nested Classes and an Introduction to Trees

G51PRG: Introduction to Programming Second semester Applets and graphics

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

HW#1: Pencil Me In Status!? How was Homework #1? Reminder: Handouts. Homework #2: Java Draw Demo. 3 Handout for today! Lecture-Homework mapping.

Final Examination Semester 2 / Year 2010

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Example: Building a Java GUI

Transcription:

CS 335 Graphics and Multimedia Image Manipulation

Image Manipulation Independent pixels: image subtraction image averaging grey level mapping thresholding Neighborhoods of pixels: filtering, convolution, etc. Geometric operations on pixels: rotation, scale, warp

Manipulating Images in Java Image class: provides simple file/network read difficult to access individual pixels easy to make into an icon BufferedImage class: simple file/network read easy access to pixels can get graphics context

Treating Pixels Independently Image Arithmetic: Change the values of pixels based on a rule which uses information from that pixel only Addition/averaging: average multiple images over time Subtraction: detect changes over time Negative: invert the color map

Image Addition

Image Subtraction

Image Subtraction

Pixel-wise Logical Operations AND XOR OR

Grey Level Mapping Remap the intensity distribution of pixels Enhances contrast between features and structures Target image grey levels Original image grey levels

Grey Level Mapping Mapping curve can be arbitrary Example: first interval is compressed, second interval is stretched Target image grey levels Original image grey levels

Grey Level Mapping Example: monotonically increasing curve (not line) Target image grey levels Original image grey levels

Grey Level Mapping Example: non-monotonically increasing curve Target image grey levels Original image grey levels

Thresholding Pixel modification based on a specified threshold criterion: newvalue = x if oldpixel < y otherwise threshold Goal: suppress values below threshold, enhance values above

Image Histograms Histogram: frequency distribution of grey levels or colors in that image Can be a strong indicator for enhancement schemes: contrast enhancement, thresholding Histograms are not unique: many images can produce the same histogram Histogram equalization: enhancement based on the histogram

Frequency Distribution Horizontal axis: grey level value Vertical axis: count 512x512 0 255

The Normalized Histogram Divide each bin by the total pixel count Bin total becomes normalized to 1

Modifying the Histogram Grey level modification will affect the histogram: 0 255 0 255

Using the Histogram for Thresholding Threshold value can be calculated from the shape of the histogram: 0 255

Localized Histograms Can compute histogram for a Region of Interest (ROI) Compute total number of pixels in ROI Compute pixel intensity distribution within ROI Can apply enhancements more locally

Histogram Equalization (Flattening) Evenly distribute intensity values across dynamic range Resulting histogram is flat Can be a complex grey level mapping: is usually easier to specify as a histogram operation

Original Image Histogram-equalized Image Intensity map to accomplish the flattening operation

Examples

Examples

Photo of the Year 2002

Take-home Exercises Ex 6.7: 1, 3, pp 132, Efford

/************************************************************ Sample: Program to load a JPEG image and display it in a JFRAME ************************************************************/ import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import com.sun.image.codec.jpeg.*; public class MyImageViewer extends JFrame { // Instance variables private BufferedImage image; // the image private MyImageObj view; // a component for display private JLabel infolabel; // a label for the GUI private int x, y; private boolean firstdrag=true;

// The Constructor for this extension of the JFrame class public MyImageViewer (String filename) throws IOException { super(filename); // Load an image from a file image = readimage(filename); // Create components to display image and pixel information view = new MyImageObj(image); infolabel = new JLabel(); infolabel.addmouselistener( new MouseAdapter() { public void mousepressed (MouseEvent event) { view.repaint(); );

// Listen for mouse events to show (x,y) coordinates on infolabel view.addmousemotionlistener( new MouseMotionAdapter() { public void mousemoved(mouseevent event) { infolabel.settext((event.getpoint()).tostring()); public void mousedragged(mouseevent event) { Graphics g = view.getimage().getgraphics(); g.setcolor (Color.white); if (firstdrag) { x = event.getx(); y = event.gety(); firstdrag = false; else { g.drawline (x, y, x=event.getx(),y=event.gety()); view.repaint(); ); view.addmouselistener( new MouseAdapter() { public void mousereleased(mouseevent event) { firstdrag = true; );

// Build the JPanel which holds (for now) the infolabel JPanel controlpane = new JPanel(); controlpane.add(infolabel); // Add the JPanel and the image data component to the JFrame getcontentpane().add(view, BorderLayout.CENTER); getcontentpane().add(controlpane, BorderLayout.SOUTH); public BufferedImage readimage (String file) throws IOException { try { FileInputStream fin = new FileInputStream(file); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fin); image = decoder.decodeasbufferedimage(); fin.close(); catch (IOException e) { return image;

public static void main(string[] argv) { // look for a command-line filename if (argv.length > 0) { try { JFrame frame = new MyImageViewer(argv[0]); frame.pack(); frame.setvisible(true); frame.addwindowlistener ( new WindowAdapter () { public void windowclosing ( WindowEvent e) { System.exit(0); ); catch (Exception e) { System.err.println(e); System.exit(1); // no command-line filename was provided else { System.err.println("usage: java MyImageViewer <imagefile>"); System.exit(1);

/***************************************************************** This is a helper object (could be described its own file) that extends JLabel so that it can hold a BufferedImage **************************************************************/ public class MyImageObj extends JLabel { // instance variable to hold the buffered image private BufferedImage image; public MyImageObj(BufferedImage img) { setimage(img); setpreferredsize(new Dimension(image.getWidth(), image.getheight())); public void setimage(bufferedimage img) { image = img; public BufferedImage getimage() { return image; public void paintcomponent(graphics g) { g.drawimage(image, 0, 0, this);