Engi 2420 structured programming lab tutorial 8
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

ENGI 2420 Structured Programming (Lab Tutorial 8) PowerPoint PPT Presentation


  • 47 Views
  • Uploaded on
  • Presentation posted in: General

ENGI 2420 Structured Programming (Lab Tutorial 8). Memorial University of Newfoundland. Assignment-8. Purpose of this assignment implement functions for image processing Structure of C++ files - assign8.h (downloadable): contains the declarations for the functions

Download Presentation

ENGI 2420 Structured Programming (Lab Tutorial 8)

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Engi 2420 structured programming lab tutorial 8

ENGI 2420Structured Programming (Lab Tutorial 8)

Memorial University of Newfoundland


Assignment 8

Assignment-8

  • Purpose of this assignment

    implement functions for image processing

  • Structure of C++ files

    - assign8.h (downloadable): contains the declarations for the functions

    - a8main.cpp (downloadable): main function that can be used as test code

    - assign8.cpp: contains your implemented functions (only submit this one via web-submit)

    - you may want to create your own test code in a separate .cpp file (do NOT submit your test code)


Data format i

Data Format (I)

  • We provide readImage and writeImage functions in a8main.cpp

  • These both use the same data format

  • The data consists of a sequence of integers. The first pair is to be interpreted as the number of rows and columns, respectively, in the image (i.e., the size of the data). The remaining numbers are the data, row by row.


Data format ii

Data Format (II)

a 5x6 image with diagonal stripes:

5 6

123 44 1 99 88 200

44 1 99 88 200 123

1 99 88 200 123 44

99 88 200 123 44 1

88 200 123 44 1 99


Threshold function i

threshold() Function (I)

  • void threshold(int src[], int rows, int cols, int dest[], int thr)

  • Convert the image in src to a binary (black and white) storing the resulting image in dest, with pixel values of only either 0 or 255. If an image pixel value is greater than thr (the threshold), then set it to 255, otherwise set it to 0

  • Do not alter the data in src


Threshold function ii

threshold() Function (II)

  • For example, if thr = 100, then src and dest should be

123 44 1 99 88 200

44 1 99 88 200 123

1 99 88 200 123 44

99 88 200 123 44 1

88 200 123 44 1 99

255 0 0 0 0 255

0 0 0 0 255 255

0 0 0 255 255 0

0 0 255 255 0 0

0 255 255 0 0 0


Blur function i

blur() Function (I)

  • void blur(int src[], int rows, int cols, int dest[])

  • Make a blurred copy of the image in src into dest. The value of each pixel in dest is calculated as the average of the corresponding pixel in src with its adjacent neighbours (normally a total of 9 pixels). Round to the nearest integer. (When the average is exactly half way between two integers, round up.)


Blur function ii

blur() Function (II)

  • for a pixel not on the edges:

  • dest[r, c] = 0.5 + (src[r-1,c-1] + src[r-1,c] + src[r-1,c+1] + src[r,c-1] + src[r,c] + src[r,c+1] + src[r+1,c-1] + src[r+1,c] + src[r+1,c+1])/9.

  • Note that, for pixels on an edge of the image or in the corner, the number of neighbours is fewer so the summation and the divisor will be different


Threshold function iii

threshold() Function (III)

  • For the diagonal stripe image example, the contents of src and dest should be

123 44 1 99 88 200

44 1 99 88 200 123

1 99 88 200 123 44

99 88 200 123 44 1

88 200 123 44 1 99

53 52 55 96 133 153 52 56 80 110 129 130 55 80 110 129 105 89 96 110 129 105 75 52 119 133 130 89 52 36


Running the program

Running the Program

  • Our main program uses a "program argument" to select the transformation (threshold or blur). 0 is for threshold and 1 is for blur

  • The default is threshold, but it is easy to change by changing the line

    int functionSelector = FUNC_THRESHOLD ; to

    int functionSelector = FUNC_BLUR ;

  • You can also select the function using the "program argument" feature of Eclipse's Run Dialog


Running with mmgood2

Running with MMGood2

  • MMGood2 is a java program that will execute your program on JPEG, PNG, or GIF files so you can see it working

  • For windows

    • Download and uncompress mmgood2.zip

    • Double click on mmgood2.bat from a Window's Explorer window


Running with mmgood21

Running with MMGood2

  • Once mmgood's main window has appeared, and you have compiled your project, you can

    • Load an input JPEG, PNG, or GIF file

    • Observe the input image


Running with mmgood22

Running with MMGood2

  • Select your assignment 8 executable. (It is in the Debug subdirectory of your project directory and, in Windows, its name will end with ".exe".)

  • Set the program argument to be 0 (threshold) or 1 (blur)

  • Run the executable


Running with mmgood23

Running with MMGood2

  • Wait patiently for your program to finish

  • Observe the output image

  • You can save it as a jpeg, if you like (use .jpg as the file name’s extension.)


  • Login