Gettysburg College

CS 111
Computer Science I

Fall 2025

Assignment 9

Due: Thu, Nov 6, by 11:59pm

General Description

screenshot

The goal of this assignment is to implement a collection of simple image processing algorithms for identifying objects in an image, including written text.

This assignment will exercise the following concepts:

  • nested loops and 2D array (matrix/table) processing
  • some of the earlier topics on strings, 1D arrays, and while loops

Preliminaries (New DrJava)

Download the new version of DrJava:

This DrJava version includes:

Preliminaries

Start DrJava and create a new project named TextReaderApp in folder cs111/hw . See the Readings List notes on how to create a new project.

For this app the phone should be put in portrait orientation.

Images and Conventions

The images for this project are available here. Download the file and extract it in the app folder TextReaderApp/res/raw/.

reader app images

Make sure only the ".png" files end up in the required folder without the ".zip" file.

Note the following (see the test cases for copyImage):

Example ImageExplanation
BLACK pixels have value 0
non-BLACK pixels have value non-0
RED pixels have value 0x00FF0000 (this is an integer even though it has letters in it)
a.png ... z.png a..z (letter images)

these are for letter images; names are lower-case, but the picture is of an upper-case letter

the letter images have dimensions rows=25,cols=23 (you may use these, sparingly, as fixed numbers)

quartz1.png
quartz2.png
taxi1.png
taxi2.png
fox1.png
fox2.png
sample (test) images for text identification
scene1.png
scene2.png
sample (test) images for object identification

Basic Image Manipulation

This part of the assignment is on writing simple image manipulation methods for:

Write the following methods:

Identifying Text in Images

This part of the assignment is on writing methods that discover letters in a text image.

The app will only work for words with distinct letters (isograms):

List of Isograms

Write the following methods:

Identifying Regions in Images

This part of the assignment is on writing methods that count the number of regions in an image and identify their boundaries.

Write the following methods:

Putting it all together

Write the following method (runTextApp) which will present the user with a menu of options to choose from.

The variable mainImage will keep track of the latest generated or loaded image. Operations such as counting regions, tracing contours, transcribing text, etc. will always use mainImage and process whatever is found there.

The variable mainTitle will show a description about the result from the latest action.

To glue the text for mainTitle use String.format(...) which is similar to System.out.printf(...):

myVarName = String.format( "The value of %s is %f which is approx %d/%d which is < %d%% error", "PI", 3.14, 22, 7, 1 );

This method is mostly given:

void runTextApp()
{
    int[][] mainImage = createLogo( "cat" );   // logo to start with -- will be replaced in some actions below

    String mainTitle = String.format( "Logo for %s", "cat" );   // latest action

    String choice = "";                        // user selection for an action (see beginning of loop)

    while ( choice.equals("Quit") == false )   // as long as choice is not "Quit"
    {

- draw main image (may have been modified)
- draw main title (description of latest action)
- wait for touch  (to see what happened so far)
screenshot

// clear the canvas 
// read an action from the user
choice = canvas.readSelection( "sOmE pRoMpT", "Load Image", "Create Logo", "Count Regions", "Trace Contours", "Transcribe Text", "Quit" );


screenshot screenshot
    
choice.equals("Load Image") == true:
    - ask for a file name: canvas.readString( "sOmE pRoMpT" )
    - replace main image: canvas.readImage( ... )
    - replace main title: "Loaded quartz.png"


screenshot
    
choice.equals("Create Logo") == true:
    - ask for a phrase, generate logo
    - replace main image with logo, replace main title


screenshot screenshot

choice.equals("Count Regions") == true:
    - count number of regions in main image
    - replace main title (see example)


screenshot screenshot

choice.equals("Trace Contours") == true:
    - find the contours in main image, replace main title
      (contours will be shown as loop starts next cycle)


screenshot screenshot

choice.equals("Transcribe Text") == true:
    - find the text in main image
    - replace main title (see example)


screenshot

choice.equals( "Add Noise" ) == true:
    - ask for the noise level: canvas.readInt( "sOmE pRoMpT" )
    - add noise to main image
      (noisy image will be shown as loop starts next cycle)
    - replace main title (see example)


    
    }
}


What to turn in

Turn in the Java code for the app in the Assignment 9 dropbox (instructions below).

This is optional: Turn in screenshots of the phone for the various operations under the given file names:

Turn in the Java code for the app in the Assignment 9 dropbox: