Tema: ejercicos
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/04/2009, 11:12
treca
 
Fecha de Ingreso: abril-2009
Mensajes: 2
Antigüedad: 15 años, 7 meses
Puntos: 0
ejercicos

Hola a todos!!
Casualmente me han enredado para que hiciera unos ejercicios (yo no sabia que eran con phyton) el caso es que no conozco el lenguaje y no los se hacer confio en que alguien me heche una mano!!!

Muchisimas gracias!!!!

os copio los ejercicios:

Exercise 2.2 Write a script that computes the runlength histogram of an image of your choice and writes it into a control file runs.dat for the plotting program gnuplot5. The control files must have the following form:
set xrange [0:30] # optional for setting xrange
plot ’-’ with impulses title ’black horizontal runs’
0 0
1 40
...
e
where the first column is the runlength and the second its frequency. You can then display the plot with gnuplot -persist runs.dat. Hints:
• Have a look at the method runlength histogram in the plugin reference. The parameters are
passed as strings.
• To iterate simultaneously over an index and its list value, you can use the Python iterator enumerate [2].
Extend your script such that it accepts command line parameters determining whether black/white or horizontal/vertical runs shall be counted (look for the argv variable in [2]).


Exercise 2.3 Write a script that measures the most frequent black vertical runlength of an image and creates an RGB image with all black vertical runs of the most frequent runlength marked in red.
Hints: You must try to create an image that only contains the runlengths that are to be marked, so that you can use highlight to mark them. All black vertical runlengths of length n are obtained by subtracting all runlengths smaller than n (filter tall runs) and all runlegths greater than n (filter short runs). Beware that these methods work in place on the image. This means that you must copy the image beforehand (image copy).
Apply your script to a music score. What do you observe?

Exercise 2.4 Do a cc analysis on an image and list all used labels in sorted order. Are the labels consecutive or are there gaps?
Hint: You can read out all labels elegantly via a Python “list comprehension” [2]:
labels = [c.label for c in ccs]
Exercise 3.1 Write a C++ plugin that flips every second white pixel of a onebit image to black.
• Call the plugin flip1 and let it change the input image.
• Call the plugin flip2 and let it return the resulting image.


Exercise 3.2 Write two variants of the plugin flip2 of the previous exercise that both access the individual pixels with get(Point(x,y)) and set in a loop over x and and y. One variant shall have the x-loop outside and one the y-loop.
Show by measuring the runtimes of both variants that it is always better in Gamera to have the outer loop vary over y and the inner loop over x. You can measure the runtime as follows:
import time
t = time.time()
res = img.flip2()
t = time.time() - t
print ("Runtime: %f" % t)

Exercise 3.3 Write a C++ plugin that replaces the pixel value at position (x, y) with the average over positions x − 1 to x + 1. In other words, an image f(x, y) shall be transformed to


The result shall be returned as a greyscale image. Find a solution for the problem that the values for white and black are exchanged in onebit and greyscale images. Hints:
• The solution consists either in the use of template specialization or a (slightly) tricky utilization of the functions black and white.
• Use NumericTraits for computing the average.
• Make sure that the sum does not go beyond the image borders.Why is it better to take care of the borders in the range of the for-loops rather than doing a range check inside the for-loops?

Exercise 4.1 Write on a sheet of paper 20 instances of one character (e.g. “a”), and on a second paper 20 instances of a different character (e.g. “b”). Make sure that all characters are a single CC (for easy segmentation with cc analysis) and scan both pages to a raster image. Plot the distribution of all of your symbols in a two dimensional feature space as follows:
• segment both images into CCs with cc analysis
• read for each CC two feature values of your choice, e.g.
feature1 = c.aspect ratio()[0]
feature2 = c.moments()[2]
• write a Gnuplot control file plot.dat of the form plot ’-’ with points title ’a’, ’-’ with points title ’b’
# feature values class a
0.7692 0.1315
...
e
# feature values class b
1.3421 2.9872
...
e
• display the plot with the command gnuplot -persist plot.dat


Exercise 4.2 Use the two images from the preceding exercise to create a training dataset containing five from each of your two characters. Write a script that uses this training dataset to recognize all characters from both images with a kNNInteractive classifier.
Try different sets of features and values of k and measure the recognition rates for both characters (recogniton rate = number of correctly classified symbols divided by the total number of symbols).