Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Graphics Expert

The Exercise

Image binarisation is a process used to simplify images for further investigation or simply to reduce the size of an image file. It simply replaces each pixel in an image with one of two possible colours (usually either black or white). The object of this coursework is for you to write an extensible Graphical User Interface (GUI) that can allow a user to load image data, in the form of text files, and perform image binarisation and to save the results.

1. The Image data file formats

There are 3 image file formats to consider in this exercise. All of them are text based and the first line in the file is the name of the format used.

i. Greyscale Image

Each line of data contains information about one pixel.

It has the form x; y; v. Where x; y are the coordinates of the pixel and v is the intensity of the pixel. The intensity ranges from 0 (black) all the way to 255 (white).

Below is the first 5 lines of the file GreyImage.txt.

Greyscale Image

61, 85, 2

69, 8, 21

39, 55, 125

46, 37, 92

2. Colour Image

Each line of data contains information about one pixel.

It has the form x; y; r; g; b. Where x; y are the coordinates of the pixel and r; g; b are the red, green and blue components of the colour.

Below is the first 5 lines of the file ColourImage.txt.

Colour Image

117, 69, 76, 85, 66

7, 126, 82, 63, 56

81, 16, 132, 146, 95

13, 178, 30, 16, 39

Your program must be able to read in files using the above 2 formats. Your program must also be able to write a file in the following Binary Image format:

i. Binary Image

This format has the form x; y; b. Where x; y are the coordinates of the pixel and b is either 0 or 1. Below is the first 5 lines of GreyImageBinaryOutput.txt.

Binary Image

61,85,0

69,8,0

39,55,1

46,37,0

2. Binarisation Methods

For a user selected threshold, t. The binarisation process works as follows:

  • For Greyscale Images if v < t then the output is 0 else it is 1.
  • For Colour Images if r+g+b/3 < t then the output is 0 else it is 1.

Automatically selecting a threshold

Your program is required to suggest a threshold to use. This is calculated in the following way:

  • For Greyscale Images t is the average of all the intensity values (v) from the image.
  • For Colour Images The intensity of a pixel is r+g+b/3. t is the average of all these computed intensity values from the image.

The suggested threshold is int(t), (since t is likely not to be a whole number).

3. Coding the solution

Your solution must follow the specification below:

Display

For the display use 2 canvas widgets, one to show the input image and one to show the result of the binarisation. The pixels in the image are to be displayed using the create_rectangle method.

Above the leftmost canvas have a label that will display the full file name of any succesfully loaded file. Above the rightmost canvas have another label with content Select Threshold (0-255) an entry box and finally a button.

Have a menu item called File which has sub-items load and save, each link to the relevant file manager window.

Once a file has been succefully loaded, its name will be displayed in the leftmost label. The suggested threshold will be computed and placed in the entry box. When the process button is pressed, the binaristaion will occur using the threshold value in the entry box. The result will be displayed in the rightmost canvas.

To successfully complete this coursework you will need to investigate the functionality available in tkinter, specifically research the canvas widget.

4. Code Provided

A structure to your program is already provided for you to download. You must use the structure provided and follow any instructions provided in these files.

  • BinaryConverter.py. This class is your GUI. You can run it and it will create a small window. Read through it carefully. You have been provided with working code to display pixels onto a canvas. The colour a create_rectangle requires is a String that follows a specific format. I have also provided a method called _determineColorValue() for each class of image which will create this String for you.
  • GUIconnect.py. An abstract class which is the parent to both ColourImage.py and GreyScaleImage.py. Read the comments in the method definitions carefully. These provide further instructions of what to write.
  • ColourImage.py and GreyScaleImage.py are where you put code specific to each file format.
  • BinaryImage.py. This class stores the result of the binarisation process and the code for the file format for saving to.

Hint: ColourImage.py, GreyScaleImage.py and BinaryImage.py are missing constructors. You will need to implement them.

Note: You may only import from tkinter. You must not import any other libraries.

Extensibility and Polymorphism

The Graphical User Interface should not be too tightly coded to binarisation approaches and their file formats. In fact we aim to have a situation that if a programmer wishes to include their own file format and binarisation approach they could include it with minimal effort. In addition if the programmer wishes to change the file format for saving the binary image, the code for your GUI (BinaryConverter) should not need to be ammended at all. To achieve this, all image types are implemented as classes that inherit from the abstract class GUIconnect (an abstract class has method definitions but with no usable method bodies). Your Graphical User Interface should communicate with these classes through the methods defined in that abstract class.

Within your Graphical User Interface use polymorphism to make the inclusion of another image file class as simple as possible.

You may always assume that the first line in an image file is a string containing the file type.

Preliminaries

Download fromMoodle BinaryConverter.py, GUIconnect.py, ColourImage.py, GreyScaleImage.py and BinaryImage.py . Place them all in the same directory of your choosing. Read through this code and understand the structure.

Finally download the test data:

GreyImage.txt, ColourImage.txt, GreyImageBinaryOutput.txt, ColourImageBinaryOutput.txt.

  • For GreyImage.txt, the suggested threshold should be 97 and the file output after saving the result is in GreyImageBinaryOutput.txt.
  • For ColourImage.txt, the suggested threshold should be 70 and the file output after saving the result is in ColourImageBinaryOutput.txt.

Attachment:- Assignment Files.rar

Computer Graphics, Computer Science

  • Category:- Computer Graphics
  • Reference No.:- M92764235

Have any Question?


Related Questions in Computer Graphics

Please read my question if you post copy and pasted code

Please read my question if you post copy and pasted code you will get a negative review. This is java In this graphical program, you are going to simulate arcade car racing game. You need a single player that is movable ...

You have a program draw a rectangle on the screen and allow

You have a program draw a rectangle on the screen and allow the user to change the color/size of the rectangle. The program will store in the browser the settings of the color/size so that upon revisiting the page, the v ...

Question a describe the architecture of simple raster

Question : a) Describe the architecture of simple raster graphics system? b) Explain raster scan display processor?

The problemsit is strongly recommended that you tackle the

The problems: It is strongly recommended that you tackle the following tasks in a modular way -- a separate standalone function for each task. Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polyg ...

The saffir-simpson hurricane scale classifies hurricanes

The Saffir-Simpson Hurricane Scale classifies hurricanes into five categories numbered 1 through 5. Write an application named Hurricane that outputs a hurricane's category based on the user's input of the wind speed. CA ...

The problemyou are to search a bitmap in rgb format and

The problem: You are to search a bitmap in RGB format and count the number of pixels which match a set of colors. The bitmap will be 1024 by 1024 pixels for the purposes of explaining this problem. The set of colors will ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As