Question: Write a program in python: Lida, inherits a piece of land. Theland is modeled as a rectangular patch of variable size. The patch of land
Write a program in python: Lida, inherits a piece of land. Theland is modeled as a rectangular patch of variable size. The patch of
land is represented with an image list of lists
To make some money out of it she can decide to lease the land to
other people. To do that, she may decide to divide the land into four
other patches. In case she decides to not lease the land, no further
subpatches are created. On the contrary, in case the land is divided
into four subpatches, some colored marks straight lines on the land
are drawn with a thickness of one pixel to mark the private properties
that are created. There is no prior knowledge of how and where the
lines will be drawn, nor which colors will be used there is no
regular pattern The only knowledge is that the lines are
axisaligned.
The four lessees that receive the subpatches of land may take the
same decision that Lida took before them. They may decide to sublease
once again their small patch to others or else, to keep the land all
for themselves. The decision for each lessee is independent of each
other. For example, lessee # may decide to sublease again, while
lessee # may keep the land for himself, etc, whereas lessee # and #
may subdivide. If they sublease and divide, they follow the same
policy of dividing in four parts and setting their boundaries with
line drawing but obviously with a different splitting position of
their land. For sure, they will be using a color that is different
from the colors used by Lida yet they will be using the same color
among them, at the same level of splitting.
NOTE: An important note is that the color of the background bg of
the land is not given ie we do not know if the bg is black, or
white or blue etc but we do know that the background land color is
NOT used by any of the lessees ever to mark their boundaries.
The subdivision process could continue until when all the lessees in
all patches stop subdividing their land. This process described here
leads us to the image that is taken as input to a program.
NOTE: You can assume that the smallest possible rectangular patch has
the shortest side of two pixels in length.
Implement a program exinputfile,
outputfile which:
reads the file indicated by the parameter 'inputfile'
using the 'images' library
preprocesses the imageif neededand implements a
recursive function to solve the requirements below.
counts all the patches of lands that are in the image and returns
the number of patches. It should return the number of rectangles
with the color of the background that is present in the
image. Regarding the simplified case below:
#
#
# a
#
# b
#
# c
#
#
the approach should return as the total number of patches. The
numbers in the simplified case above are just added for the sake
of clarity. The image data does not contain those numbers,
obviously
finally, given that the real estate registry needs to bookkeep
all the boundaries created, the program shall build an output
image of the size of xN The image encodes as the first pixel
the color of the background. Then it should encode "the color
hierarchy" of all the N colors used to subdivide the patches of
land. The hierarchy is defined by "visiting" first in depth the
upper left patch, then upper right patch, then lower left, and
lower right. The colors should be stored in reverse order with
respect to the "visit" made. With reference to the previous
semplified case, assuming a boundary color is described with a
letter, the output image should contain:
outcolors bg b c a
NOTE: it is forbidden to importuse other libraries or open files
except the one indicated
NOTE: The test system recognizes recursion ONLY if the recursive
functionmethod is defined in the outermost level. DO NOT
define the recursive function within another functionmethod
otherwise, you will fail all the tests.
import images
def exinputfile, outputfile:
# write your code here
pass
if namemain:
# write your tests here
passWrite a program in w wwwwwwww
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
