Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#PYTHON# 3. Color sensor demosaicing 440pts As discussed in class, there are several steps to transform raw sensor measurements into nice looking images. These steps
#PYTHON#
3. Color sensor demosaicing 440pts As discussed in class, there are several steps to transform raw sensor measurements into nice looking images. These steps include Demosaicing, White Balancing and Gamma Correction. In this problem we will implement the demosaicing step. (see Szeliski Chapter 2.3) In the assignment data directory on Canvas there is a zip file containing raw images from a Canon 20D camera as well as corresponding JPEG images from the camera (*. JPG ). The raw image files (* . CR2 ) have been converted to 16-bit PGM images (*.pgm) using David Coffin's dcraw program to make it easy to load them in as arrays using the supplied code below read pgm RGRGRGR GGG G GGI G GBGBGBG Bayer RGGB mosaic The raw image has just one value per pixel. The sensor is covered with a filter array that modifies the sensitivity curve of each pixel. There are three types of filters: "red", "green", and "blue", arranged in the following pattern repeated from the top left corner: G B Your job is to compute the missing color values at each pixel to produce a full RGB image (3 values at each pixel location). For example, for each "green" pixel, you need to compute "blue" and "red" values. Do this by interpolating values from adjacent pixels using the linear interpolation scheme we described in class. in [ ]:|# # these are the only modules needed for problem #3 import numpy as np import matplotlib.pyplot as plt # this function will load in the raw mosaiced data stored in the pgm fil. def read_pgm(filename): Return image data from a raw PGM file as a numpy array Format specification: http:/etpbm.sourceforge.net/doc/pgm.html infile open (filename, r',encoding-"ISO-8859-1") # read in header magic infile.readline() width, height -[int (item) for item in infile.readline().split)] maxval infile.readline() # read in image data and reshape to 2D array, convert 16bit to float image - np.fromfile(infile, dtype'>u2").reshape( (height, width)) image-image.astype (float)/65535. return image Implement a function demosaic which takes an array representing the raw image and returns a standard color image. To receive full credit, you should implement this using NumPy indexing operations like you practiced in the first part of the assignment. You should not need any for loops over individual pixel locations. You can accomplish this by either using array subindexing or alternately by using the imfilter function with the appropriate choice of filter. In def demosaic(I) 11u Demosaic a Bayer RG/GB image to an RGB image. Parameters I numpy.array (dtype-float) RG/GB mosaic image of size HxW Returns numpy.array (dtype-float) Hxwx3 array containing the demosaiced RGB image #[enter your code here] 3. Color sensor demosaicing 440pts As discussed in class, there are several steps to transform raw sensor measurements into nice looking images. These steps include Demosaicing, White Balancing and Gamma Correction. In this problem we will implement the demosaicing step. (see Szeliski Chapter 2.3) In the assignment data directory on Canvas there is a zip file containing raw images from a Canon 20D camera as well as corresponding JPEG images from the camera (*. JPG ). The raw image files (* . CR2 ) have been converted to 16-bit PGM images (*.pgm) using David Coffin's dcraw program to make it easy to load them in as arrays using the supplied code below read pgm RGRGRGR GGG G GGI G GBGBGBG Bayer RGGB mosaic The raw image has just one value per pixel. The sensor is covered with a filter array that modifies the sensitivity curve of each pixel. There are three types of filters: "red", "green", and "blue", arranged in the following pattern repeated from the top left corner: G B Your job is to compute the missing color values at each pixel to produce a full RGB image (3 values at each pixel location). For example, for each "green" pixel, you need to compute "blue" and "red" values. Do this by interpolating values from adjacent pixels using the linear interpolation scheme we described in class. in [ ]:|# # these are the only modules needed for problem #3 import numpy as np import matplotlib.pyplot as plt # this function will load in the raw mosaiced data stored in the pgm fil. def read_pgm(filename): Return image data from a raw PGM file as a numpy array Format specification: http:/etpbm.sourceforge.net/doc/pgm.html infile open (filename, r',encoding-"ISO-8859-1") # read in header magic infile.readline() width, height -[int (item) for item in infile.readline().split)] maxval infile.readline() # read in image data and reshape to 2D array, convert 16bit to float image - np.fromfile(infile, dtype'>u2").reshape( (height, width)) image-image.astype (float)/65535. return image Implement a function demosaic which takes an array representing the raw image and returns a standard color image. To receive full credit, you should implement this using NumPy indexing operations like you practiced in the first part of the assignment. You should not need any for loops over individual pixel locations. You can accomplish this by either using array subindexing or alternately by using the imfilter function with the appropriate choice of filter. In def demosaic(I) 11u Demosaic a Bayer RG/GB image to an RGB image. Parameters I numpy.array (dtype-float) RG/GB mosaic image of size HxW Returns numpy.array (dtype-float) Hxwx3 array containing the demosaiced RGB image #[enter your code here]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started