Information Technology | Graphics » Blemish Correction on Images

Datasheet

Year, pagecount:2017, 4 page(s)

Language:English

Downloads:3

Uploaded:November 16, 2023

Size:664 KB

Institution:
-

Comments:

Attachment:-

Download in PDF:Please log in!



Comments

No comments yet. You can be the first!

Content extract

CS1112 2017 Project 4 due Thursday, 3/30, at 11pm You must work either on your own or with one partner. If you work with a partner you must first register as a group in CMS and then submit your work as a group. Adhere to the Code of Academic Integrity For a group, “you” below refers to “your group.” You may discuss background issues and general strategies with others and seek help from the course staff, but the work that you submit must be your own. In particular, you may discuss general ideas with others but you may not work out the detailed solutions with others. It is not OK for you to see or hear another student’s code and it is certainly not OK to copy code from another person or from published/Internet sources. If you feel that you cannot complete the assignment on you own, seek help from the course staff. Objectives Completing this part of the project will solidify your understanding of 2-dimensional and 3-dimensional arrays. You will also work with the jpeg image

format and the type uint8. Pay attention to the difference between uint8 and Matlab’s default type double. Ground Rule As before, do not use the break or continue commands. Part A, specifying problems 1 and 2, is in a separate document. 3 Averaging uint8 values Implement the following function as specified: function [rAve, cAve] = averagesAtMin(M) % Let r and c be the row and column indices of the minimum value in uint8 matrix M. % rAve is the mean of the values in row r of matrix M. % cAve is the mean of the values in column c of matrix M. % rAve and cAve should be uint8 scalars (round as appropriate). The only built-in functions that are allowed in this problem are size, uint8, and double. Recall that the type name can be used as a function name to do type conversion, e.g, p=uint8(pi) will create a variable p of type uint8 that stores the integer value 3. Do not convert the whole matrix M to type double as doing so would require eight times the amount of memory to store the

entire matrix. Use type double only in the parts of the code that absolutely requires double for computation. 4 Blemish Correction on Images Along with the different filters and effects available through popular photo editing software, a common editing tool is a blemish remover. A basic blemish remover allows the user to identify the location of a blemish in an image and then covers up the blemish by calculating a new color value for the pixels that make up the blemish. You will develop such a blemish correction tool in Matlab that allows the user to select and correct multiple blemishes. Original Image Image with two blemishes removed 1 Start by watching the demonstration of our Matlab blemish correction program, available on the Projects page of the course website. Observe the following: • The program starts with displaying the image. • The title area of the figure window displaying the image gives instructions to the user. • The user selects a blemish by clicking

around it; a click that is very close to the first click on a blemish completes the selection of that blemish. Then the software corrects the blemish by assigning to the pixels in a circular area the color computed from the nearby pixels. After the correction, the user can click on the image again to start the selection of another blemish or click outside the image in the grey area to stop any further selection. • Once the selection of a blemish has begun, if the user clicks outside the image, the program uses the previous click (which was still on the image) to “close” the blemish selection and then does the correction. • A file blemishfixed.jpg containing the corrected image is saved to the current folder before the program ends You will build this blemish corrector for color images in a modular fashion by implementing a set of four functions to handle these tasks: (1) approximate the blemish area as a circular area, (2) compute the median color from the pixels that surround

the circular blemish area, (3) replace the color of the pixels inside the circular blemish area with the calculated median color, and (4) deal with user interactionshow the (updated) image and instructions, accept and evaluate user clicks, and write the jpeg file containing the final updated image. 4.1 Approximating the blemish area as a circular area Implement the following function as specified: function [x, y, r] = centroidCalculator(im, ux, uy) % Return the centroid of a set of points selected by the user and the mean % distance from the centroid. % im is a 3-D uint8 array representing an image. % Scalars ux and uy are the coordinates of one point marking the blemish % (the first point that the user had clicked to start selecting a blemish). % This function accepts user clicks until the user clicks the same point as % the starting point (within a reasonable tolerance) or until the user % clicks outside of the image. Mark each clicked point inside the image % with an asterisk and

connect each point to the previous point with % a line. % Scalars x and y are the coordinates of the centroid of all the clicked % points INSIDE the image. Round x and y to integers % Scalar r is the mean distance between a clicked point and the centroid, % excluding any point outside the image. Round r to an integer % Thus, the circle centered at (x,y) with the radius r approximates the % area of the blemish. % This function assumes that a figure window showing the image is already % open. (This is handled by function multipleBlemishes) A note on the relationship between the “coordinates” and the row and column indices of image data: The statement [a,b] = ginput(1) assigns to variable a the x-coordinate of a user-clicked point and to variable b the y-coordinate. The x-coordinate maps to the column index while the y-coordinate maps to the row index. For example, if a user clicked point has x-coordinate 5.8 and y-coordinate 201, the nearest corresponding data point in the uint8

array is at row 20 and column 6. Be sure to round the coordinates so that you can use them as indices 4.2 Median color surrounding the circular blemish area In lecture, we implemented a function that calculated the median values of a grayscale image. The median calculation here is slightly different because we are dealing with a color image If one were to calculate the median color using the RGB color representation, then one would calculate the median red, the median blue, and the median green values separately. The resulting RGB values do not generally translate to an accurate representation of the median color. For this reason, we will first convert the image data to the HSV color representation for finding the median color. The abbreviation “HSV” stands for “hue,” “saturation,” and “value,” and it is a commonly used color model. “Hue” represents the color/shade of a pixel “Saturation” represents the amount of gray in 2 the pixel. The less saturated a

pixel is, the more washed-out it appears; the more saturated it is, the more vibrant it appears “Value” represents the brightness of the pixel You can learn more on the HSV color model at http://en.wikipediaorg/wiki/HSL and HSV if you wish Now we can take the median of the hue, saturation, and value separately and achieve an accurate median color of an area and then convert the values back to the RGB representation. The statement Q = rgb2hsv(P) converts the uint8 array P storing RGB data to the type double array Q storing HSV data, with each value in the range of 0 to 1, inclusive. Q will have the same dimensions as P (for color images). The function hsv2rgb works analogously to convert from the HSV model to the RGB model, but returns type double values, each in the range of 0 to 1, inclusive. We will need to scale the values back to the range of 0 to 255, inclusive, and convert back to the type uint8. Implement the following function as specified: function mRGB =

findMedReplacement(im, x, y, r) % Returns mRGB, the median RGB values of the pixels that lie in the ring % formed between a circle centered at (x,y) with r and a circle centered % at (x,y) with radius 2*r. % The image is first converted from RGB to an HSV representation so that % median calculations can be done on the hue, saturation, and value % separately. The median values are then converted back to RGB % mRGB is a 1x1x3 uint8 array storing RGB values, in the range 0.255, inclusive Note that the pixels inside the circular area of the blemish are not included in the median calculation. 4.3 Correct values in the circular blemish area Implement the following function as specified: function imNew = blemishCorrector(im, x, y, r) % Replace the values of the pixels that lie inside the blemish’s circular % area with the median color returned from function findMedReplacement. % (This function should call function findMedRepalcement.) % im is a 3-D uint8 array representing an image. %

Scalars x, y, and r are positive integers. The pixels to be corrected % are the ones that lie inside the circle centered at (x,y) with a radius % of r. % imNew is im but with the appropriate pixel values replaced. 4.4 Show image and run blemish correction for multiple user-selected blemishes By making effective use of the functions above, implement the following function as specified: function multipleBlemishes(imfile) % Show image named by imfile and correct the blemishes selected by the user. % imfile is a string naming a jpeg color image. % Display the image. Allow the user to select a blemish using mouse clicks % around the blemish. Then correct the blemish by assigning to the pixels % that lie in a circular area approximating the blemish area the median % color calculated from the pixels that surround the blemish. The user can % select another blemish to correct by clicking in the image again or % quit the program by clicking outside the image. The image with all the % selected

blemishes fixed is saved in the file ’blemishfixed.jpg’ in the % current directory. Instructions to the user should appear in the title % area of the figure window throughout program execution. % This function calls functions centroidCalculator and blemishCorrector. Have fun correcting images! Then submit your files multipleBlemishes.m, centroidCalculatorm, findMedReplacement.m, and blemishCorrectorm on CMS Revised 3/27: submit also averagesAtMin.m 3 Final note: In the blemish correction problem you may have used vectorized code and the built-in functions sum, mean, and median. That’s fine for Problem 4 in this project But some time before the next prelim, be sure to try solving this problem without vectorized code and without sum and mean. That would require more use of nested loops and allow you to practice basic array algorithms (such as traversing, summing rows and columns, etc.) It’s excellent practice for working with arrays and loops! 4