Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Image Printing Program Based on Halftoning The following figure shows ten shades

ID: 3792972 • Letter: I

Question

Image Printing Program Based on Halftoning The following figure shows ten shades of gray approximated by dot patterns. Each gray level is represented by a 3 times 3 patted of black and white dots. A 3 x 3 area full of black dots is the approximation to gray-level black, or 0. Similarly, a 3 times 3 area of white dots represents gray level 9, or white. The other dot patterns are approximations to gray levels in between these two extremes. A gray-level printing scheme based on dots patterns such as these is called "halftoning." Note that each pixel in an input image will correspond to 3 times 3 pixels on the printed image, so spatial resolution will be reduced to 33% of the original in both the vertical and horizontal direction. Size scaling as required m (a) may further reduce resolution, depending on the size of the input image. Write a halftoning computer program for printing gray-scale images based on the dot patterns just discussed. Your program must be able to scale the size of an input image so that it does not exceed the area available in a sheet of size 8.5 times 11 inches (21.6 times 27.9 cm). Your program must also scale the gray levels of the input image to span the full halftoning range. Write a program to generate a test pattern image consisting of a gray scale wedge of size 256 times 256, whose first column is all 0's, the next column is all 1's, and so on, with the last column being 255's. Print this image using your gray-scale printing program. Print book Figs. 2.22(a) through (c) using your gray-scale printing program. Do your results agree with the conclusions arrived at in the text in pgs. 64-65 and Fig. 2.23? Explain.

Explanation / Answer

function result_image = halftone(input_image) % input image to halftone
minimum = min(min(input_image));
maximum = max(max(input_image));
step = (maximum-minimum)/10);
middle_image = zeros(size(input_image));
for k=0:9
l_min= min+step + k;
l_max = l_min + step;
[i,j] = ind2sub(size(input_image), find(input_image>=lmin&input_image<=lmax));
for l = 1:length(i)
   middle_image(i(l),j(l)) = k;
end
end
middle_image
w=l; % for white and black circules
b=0;
gray0 = [b,b,b;b,b,b;b,b,b];
gray1 = [b,w,b;b,b,b;b,b,b];
gray2 = [b,w,b;b,b,b;b,b,w];
gray3 = [w,w,b;b,b,b;b,b,w];
gray4 = [w,w,b;b,b,b;w,b,w];
gray5 = [w,w,w;b,b,b;w,b,w];
gray6 = [w,w,w;b,b,w;w,b,w];
gray7 = [w,w,w;b,b,w;w,w,w];
gray8 = [w,w,w;w,b,w;w,w,w];
gray9 = [w,w,w;w,w,w;w,w,w];

result_image = zeros(size(middle_image)+3);
for i=1:size(middle_image,1)
   for j=1:size(middle_image,2)
       switch middle_image(i,j)
           case 0
                 level = gray0;
           case 1
                level = gray1;
           case 2
                level = gray2;
           case 3
                level = gray3;  
           case 4
                level = gray4;      
            case 5
                level = gray5;
            case 6
                level = gray6;
           case 7
                level = gray7;  
           case 8
                level = gray8;
            case 9
                level = gray9;
       end
           new_i = i +2*(i-1);
           new_j = j +2*(j-1);
           result_image(new_i:new_i+2;new_j+2) = level;
   end  
end
  
clc;clear all; close all; % clear screen of matlab tool
file_in = 'face.jpg';
input_path=['C:UsersDownloadspic_opt.jpg' file_in]; %input image file path
input_image = imread(input_path); %read the input image
figure, imshow(input_image), title('input image');
file_out = ['halftone-' file_in];
output_path=['/imout/images/' file_out];
result_image= halftone(input_image);
figure,imshow(result_image),title('halftone image'); %show the image on matlab tool screen
imwrite(result_image,output_path);   %write the image to output path