Implement methods for a quadtree representation of bitmap
images.
Our representation of quadtrees will not have a separate Node
class. Instead, a QuadtreeBitmap itself can be thought of as a node.
A QuadtreeBitmap is either a leaf, in which case it represents a
square region of pixels all of the same colour; or an internal node, in
which case it has four child QuadtreeBitmaps, one per quadrant of
the bitmap image.
You may implement your submission in either Java or Python. The
only file which you need to edit is QuadtreeBitmap.java or
quadtree_bitmap.py, which contains a class QuadtreeBitmap, which
contains the methods you need to implement:
• blackenNorthWestQuadrant() : blacken the entire north-west
quadrant.
• countPixels(Colour) : count pixels of a given colour in the bitmap
represented by the quadtree.
• invertColours() : invert the colours in the bitmap represented by
the quadtree, i.e. turn every black pixel white and every white
pixel black.
• setPixel(int x, int y, Colour) : change the colour of a single pixel in
the bitmap represented by the quadtree, to the specified
colour.
• computeOverlay(QuadtreeBitmap bmp1, QuadtreeBitmap bmp2) :
construct and return the overlay of the two input images of the
same size. In the overlay a pixel is black if either of the input
images has a black pixel in the same location. That is, a pixel
in the output image is white only when the corresponding pixel
in both input images is white, otherwise the output pixel is
black. Rather than do the operation pixel by pixel, one can
compute the overlay more efficiently by leveraging the
quadtree's ability to represent multiple pixels with a single
node.
Note: for full marks, the resulting quadtree needs to be in "reduced"
form, i.e. any subtree that is entirely one colour needs to be
reduced to a single leaf.
Empty method definitions have been provided in the QuadtreeBitmap
class for each of the methods you need to implement. They start
from line 115 of the Java scaffold, and from line 90 of the Python
scaffold.
We have provided a scaffold which includes many helpful things,
such as:
• A method which constructs a QuadtreeBitmap from a string
representation. See below for details on the string
representation format expected.
• A method which converts a QuadtreeBitmap into a string
representation.
• Various constructors which you might find helpful, e.g.
◦ A constructor which creates a leaf QuadtreeBitmap for a
given location and size.
◦ A constructor which creates a QuadtreeBitmap for a given
location and size, with quadrants given by a list of
QuadtreeBitmaps provided as an argument.
• Convenience methods, e.g.
◦ A method which enumerates quadrants in the following
order: northeast, northwest, southeast, southwest.
◦ A method which determines which quadrant an input (x,
y) coordinate pair lies within. (If any.)
◦ A convenience method which you may enable, which
reads a string representation of a bitmap from standard
input and constructs the corresponding QuadtreeBitmap.
◦ Methods which generate string representations of a
QuadtreeBitmap, both as a string representation of the
bitmap it encodes, and with boxing interspersed to depict
its tree structure.
A main method, which will not be tested, has also been provided
and may be used by you for experimentation/testing: it's at line 178
of the Java scaffold and at the top of the Python scaffold. If you run
the scaffold code in its initial state, you will be asked to enter a
string representing a bitmap. Try entering the example from the
sheet:
Text
........
.....***
...***..
..**....
..*.....
.**...**
**...***
*....***
We advise against changing the other methods provided in the
scaffold. You are allowed to write additional methods, classes, etc.,
and add additional source files to your assignment workspace as
you see fit, though take note of the University's plagiarism policy.
Colour.java
LANGUAGE
QuadtreeBitmap.java
build.sh
core.py
quadtree_bitmap.py
run.sh
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。