Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The signature of ImageBlob is ImageBlob also for the pointers, ImageBlob NW, NE, SW, SE Public methods are acceptable for ImageBlob but no imports from

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

The signature of ImageBlob is ImageBlob also for the pointers, ImageBlob NW, NE, SW, SE

Public methods are acceptable for ImageBlob but no imports from library except Scanner and File to read the pgm file

In java pls, thank you

Let's now see how an image can be stored efficiently with a quadtree. For illustration purposes only, we will demonstrate the process for a special type of grayscale image, called bitmap. Pixels in a bitmap can only take two of the 256 possible values, either black or white. In Figure 2 we have an 8x8 bitmap on the left and the respective quadtree on the right. The leafs of the tree represent regions of pixels that have the same color. These nodes don't need any children because they can efficiently represent the whole region by using three values only: the two coordinates of the region's origin, and the color. Inner nodes, on the other hand, represent regions of pixels that do not have the same color. Even if it's a single pixel in the whole region that has a different color from the rest, the region needs to be further subdivided. Keep in mind that all inner nodes must have exactly 4 children representing the 4 sub-quadrants. Obviously, leafs can be as small as 1x1, while inner nodes can't be smaller than 2x2. In Figure 2, leafs are depicted with the color of their region (either black or white), while inner nodes with gray. The root of the tree represents the whole image and can be either a leaf or an inner node. The four children/subquadrants of an inner node must follow a predetermined spatial order; in this figure it's a clockwise order (see 1-2-3-4) but, in general, it can be any fixed order you want. 8 x 8 1 2 3 4 4x4 2 x 2 1 2 1 pixel 4 3 Figure 2: Quadtree for a bitmap (source: wikipedia) You may NOT: . Add additional public methods, variables, or classes. Exceptions: you may add public methods in ImageBlob and in private nested classes, and you may also override Object's public methods like equals, toString, etc. Use any built in Java Collections Framework classes in your program (e.g. no LinkedList, ArrayList, etc.). Add any additional import statements (or use the fully qualified name to get around adding import statements). Store anywhere in your program the Pixel[][] array that was passed to the QuadTree Image constructor. This array is used only for constructing the quadtree. Violation of this rule will result in a 0 on the entire assignment. class ImageBlob This class represents a single node in the quadtree structure. You may not alter or add any fields. Pixel value The value of the pixel if the node is a leaf or null if it's an inner node. ImageBlob NW, NE, SE, SW The four pointers to the children nodes (in clockwise order). class QuadTreeImage This class is the most important component of this project. It uses a quadtree structure to represent a grayscale image and provides various methods for processing the tree (a.k.a. image). The generic type Pixel can be any subtype of java.lang.Number. The class must implement the Comparable and the Iterable interfaces. The above signature is obviously not complete. QuadTree Image (Pixel[][] array) The constructor builds the quadtree from an array that holds the original data read from the PGM file. You may not store the array (or the pointer to the array) anywhere in your program after the creation of the tree. Pixel getColor(int w, int h) Returns the value of the pixel at location w, h where w and h are the column and row indexes in the original image respectively. If the coordinates w and h are invalid, it throws an IndexOutOfBoundsException. You may not make any use of this method anywhere outside the method exportImage. It will result in 0 points for any method that violates this restriction. The same is true if you try to bypass the restriction by building your own helper method that has the same or a similar functionality. final class Utilities It contains two utility methods that we need in order to read/write images from/to files. static Short[][] loadFile(String pgmFile) It reads a PGB image from a file and stores the data in an array of type Short. Modifying the return type of this method to Integer or Float should not affect the rest of your program since everything else in this project is using generics. Let's now see how an image can be stored efficiently with a quadtree. For illustration purposes only, we will demonstrate the process for a special type of grayscale image, called bitmap. Pixels in a bitmap can only take two of the 256 possible values, either black or white. In Figure 2 we have an 8x8 bitmap on the left and the respective quadtree on the right. The leafs of the tree represent regions of pixels that have the same color. These nodes don't need any children because they can efficiently represent the whole region by using three values only: the two coordinates of the region's origin, and the color. Inner nodes, on the other hand, represent regions of pixels that do not have the same color. Even if it's a single pixel in the whole region that has a different color from the rest, the region needs to be further subdivided. Keep in mind that all inner nodes must have exactly 4 children representing the 4 sub-quadrants. Obviously, leafs can be as small as 1x1, while inner nodes can't be smaller than 2x2. In Figure 2, leafs are depicted with the color of their region (either black or white), while inner nodes with gray. The root of the tree represents the whole image and can be either a leaf or an inner node. The four children/subquadrants of an inner node must follow a predetermined spatial order; in this figure it's a clockwise order (see 1-2-3-4) but, in general, it can be any fixed order you want. 8 x 8 1 2 3 4 4x4 2 x 2 1 2 1 pixel 4 3 Figure 2: Quadtree for a bitmap (source: wikipedia) You may NOT: . Add additional public methods, variables, or classes. Exceptions: you may add public methods in ImageBlob and in private nested classes, and you may also override Object's public methods like equals, toString, etc. Use any built in Java Collections Framework classes in your program (e.g. no LinkedList, ArrayList, etc.). Add any additional import statements (or use the fully qualified name to get around adding import statements). Store anywhere in your program the Pixel[][] array that was passed to the QuadTree Image constructor. This array is used only for constructing the quadtree. Violation of this rule will result in a 0 on the entire assignment. class ImageBlob This class represents a single node in the quadtree structure. You may not alter or add any fields. Pixel value The value of the pixel if the node is a leaf or null if it's an inner node. ImageBlob NW, NE, SE, SW The four pointers to the children nodes (in clockwise order). class QuadTreeImage This class is the most important component of this project. It uses a quadtree structure to represent a grayscale image and provides various methods for processing the tree (a.k.a. image). The generic type Pixel can be any subtype of java.lang.Number. The class must implement the Comparable and the Iterable interfaces. The above signature is obviously not complete. QuadTree Image (Pixel[][] array) The constructor builds the quadtree from an array that holds the original data read from the PGM file. You may not store the array (or the pointer to the array) anywhere in your program after the creation of the tree. Pixel getColor(int w, int h) Returns the value of the pixel at location w, h where w and h are the column and row indexes in the original image respectively. If the coordinates w and h are invalid, it throws an IndexOutOfBoundsException. You may not make any use of this method anywhere outside the method exportImage. It will result in 0 points for any method that violates this restriction. The same is true if you try to bypass the restriction by building your own helper method that has the same or a similar functionality. final class Utilities It contains two utility methods that we need in order to read/write images from/to files. static Short[][] loadFile(String pgmFile) It reads a PGB image from a file and stores the data in an array of type Short. Modifying the return type of this method to Integer or Float should not affect the rest of your program since everything else in this project is using generics

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions