Question: Matlab need help my psedocode and my code and the testing img are below. psedocode: function output = halftone(input) img = read image (img_file) //
Matlab need help my psedocode and my code and the testing img are below.



psedocode:
function output = halftone(input)
img = read image (img_file)
// create 10 dot patterns in 3 dimensional matrix for example dots(:,:,1) = [0,0,0; 0,0,0; 0,0,0];
dots is 3 dimensional matriux should be
// size of dots is = 3, 3, 10
[row, cols] = size (input);
// loop through the input image doing the following;
// computer the average value over 3*3 pixel block.
// use this average value to copy the appropriate dot pattern to the output image.
// if the dimensions of the input iamge are not multiples of three then treat the edges as special cases
// If the dimensions of the input image are not multiples of three then treat the edges as special case:
// if the dimension of the input imnage are not mutiples of three then treat the edges as special cases
// - compute average over whatevr size block is at edge of image (2* 3)
// -use this value to copy poart of the appropriate dot pattern to the output image 2* 3 block for example.
for r = 1:3 rows
for c= 1: 3 cols
compute average over 3 *3 in input image
use linear interpolation to map this average to the integer 0-9
END
copy the appropriate dot pattertn to the output image
end
// special case for column dimentiuon not mutiple of 3
...
end
//special case for tow dimension not multiple of 3.
the code so far:
Function: function outImage = halftone(inImage) [m,n] = size(inImage); mp = ceil(m/3)*3; np = ceil(n/3)*3; Image = 255*ones(mp,np); Image(1:m,1:n) = inImage; s =3; pattern = zeros(s,s,s*s+1); pattern(:,:,1) = zeros(3); pattern(:,:,2) = [0 255 0;0 0 0; 0 0 0]; pattern(:,:,3) = [0 255 0;0 0 0; 0 0 255]; pattern(:,:,4) = [255 255 0;0 0 0; 0 0 255]; pattern(:,:,5) = [255 255 0;0 0 0; 255 0 255]; pattern(:,:,6) = [255 255 255;0 0 0; 255 0 255]; pattern(:,:,7) = [255 255 255;0 0 255; 255 0 255]; pattern(:,:,8) = [255 255 255;0 0 255; 255 255 255]; pattern(:,:,9) = [255 255 255;255 0 255; 255 255 255]; pattern(:,:,10)= [255 255 255;255 255 255; 255 255 255]; upImage = zeros(m,n); pnm = zeros(m,n); for i=1:mp/3 for j=1:np/3 avgInImage = mean(mean(Image((i*3-2):(i*3),(j*3-2):(j*3)))); pn = ceil(avgInImage/(256/(s*s+1))); upImage((i*3-2):(i*3),(j*3-2):(j*3)) = pattern(:,:,pn); end end upImage = uint8(upImage); outImage = upImage(1:m,1:n); end
Title: Binary Image Rendering using Halftoning Halftoning is a technique that uses patterns of black and white dots to simulate a grayscale image. It is useful when an output device can only print or display black or white. The figure below shows 3x3 patterns of black and white dots that you will use to represent blocks of 3x3 pixels in grayscale images. That is, the input will be a grayscale image whose pixels have values from 0 to 255 and the output will be an image that only contains two values, one corresponding to black and the other to white 0 (Ignore the fact that the dots above are circular. They should really be square.) Your assignment: a) In MATLAB, write the function halftone that takes a grayscale image with values 0-255 as its input (this input should be a matrix, not a filename) and returns a binary (two-valued) image (again a matrix) as its output. The input and output should be of type uint8. Your function should use the 10 dot patterns above to transform the grayscale image to the binary image. You will have to decide on this transformation. Importantly, your input and output images should have the same size (number of pixels). Include the code for this function in your lab report. Write a test script that generates a test pattern image consisting of a gray scale "wedge" of size 256x256, whose first row is al1 0, the next row is all1, and so on, with the last row being 255 b) Convert this image using your halftoning function. Include the original and halftone images in your lab report. Include this test script in your report. Title: Binary Image Rendering using Halftoning Halftoning is a technique that uses patterns of black and white dots to simulate a grayscale image. It is useful when an output device can only print or display black or white. The figure below shows 3x3 patterns of black and white dots that you will use to represent blocks of 3x3 pixels in grayscale images. That is, the input will be a grayscale image whose pixels have values from 0 to 255 and the output will be an image that only contains two values, one corresponding to black and the other to white 0 (Ignore the fact that the dots above are circular. They should really be square.) Your assignment: a) In MATLAB, write the function halftone that takes a grayscale image with values 0-255 as its input (this input should be a matrix, not a filename) and returns a binary (two-valued) image (again a matrix) as its output. The input and output should be of type uint8. Your function should use the 10 dot patterns above to transform the grayscale image to the binary image. You will have to decide on this transformation. Importantly, your input and output images should have the same size (number of pixels). Include the code for this function in your lab report. Write a test script that generates a test pattern image consisting of a gray scale "wedge" of size 256x256, whose first row is al1 0, the next row is all1, and so on, with the last row being 255 b) Convert this image using your halftoning function. Include the original and halftone images in your lab report. Include this test script in your report
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
