# lab1_2.py -- template for your Task #2 design file import numpy import matplotlib.pyplot as p import channel reload(channel) import im1d reload(im1d) import lab1 reload(lab1) p.ion() # interactive plot mode def fix_image(rcvdimage, orig_length, mark_length): """ Your delay eliminating program goes here, you should return a numpy array of floats of length orig_length. """ return rcvdimage # testing code. if __name__ == '__main__': # Read in a .png image as array of greyscale values # between 0.0 and 1.0 image = im1d.im1dread("brobot") num_pixels = len(image) # Show the image im1d.im1dshow(image,rows=512) # Create a noisy channel mychannel = channel.channel(channelid='2',noise=0.1) # Treat the image data as voltages and just send through # noisy channel rcvdimage = mychannel(image) # Show the rcvd image p.figure() im1d.im1dshow(rcvdimage,rows=512) # Mark the start of an image with twenty voltage # samples = 1.0 volt followed by twenty zero volt samples mark_len = 20 # Create an array of all ones marked = numpy.ones(2 * mark_len + num_pixels) # Overwrite the samples after the ones part of the mark # with zeros marked[mark_len:2*mark_len] = 0 # Overwrite image marked[2*mark_len:] = image[:] # Create a noisy channel with random delay and padding mychannel = channel.channel(channelid='2',noise=0.1, random_tails=200) # Send image through noisy, random delayed, random padded # channel rcvdimage = mychannel(marked) # Show the rcvd image assuming no delay # try running a few times) p.figure() im1d.im1dshow(rcvdimage[2*mark_len:2*mark_len+len(image)], rows=512) # Show the fixed rcvd image based fixed_image = fix_image(rcvdimage, num_pixels, mark_len) if len(fixed_image) == num_pixels: # Get a new figure p.figure() im1d.im1dshow(fixed_image,rows=512) else: print "Image from fix_image NOT the right size!!!" # enable the following line whey you're ready to submit # your code to the on-line server #lab1.checkoff(fix_image,'L1_2')