实验要求:

Image Printing Program Based on Halftoning

Objective:

To know in principle what is “halftoning”, the definition of resolution, and how to print an image in a mono-chromosome printer.

Main requirements:

Ability of programming with C, C++, or Matlab.

Instruction manual:

The following figure shows ten shades of gray approximated by dot patterns. Each gray level is represented by a 3 x 3 pattern 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 x 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 x 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 in (a) may further reduce resolution, depending on the size of the input image.

(a) 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 x 11 inches (21.6 x 27.9 cm). Your program must also scale the gray levels of the input image to span the full halftoning range.

(b) Write a program to generate a test pattern image consisting of a gray scale wedge of size 256 x 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.

(c) 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. 61-62 and Fig. 2.23? Explain. You will need to download Figs. 2.22(a) through (c).

实验要求是英文的,不懂的词查查字典就行了,这里就不翻译了。

这里简单介绍一下:

Halftoning, 意思是半色调(技术),而在前面的英文实验要求中详细介绍了其原理。

我们主要看下面这幅图:



假设一幅灰度图像,那么我们知道它的每个像素都有一个对应的灰度值,通常这个灰度的取值范围是 0 ~ 255,即 8 bit 灰度级。而半色调技术的意思就是,如图中所示,将灰度级压缩,划分成 10 个灰度级,取值范围是 0 ~ 9。我们想将以前的图像的一个像素,用现在的一个 3 * 3的矩阵表示,它在原图像中的像素值是一个 0 ~ 255 的数, 在 0 ~ 255 内10等分,即像素灰度值除以25.6,则其像素值就会对应图中的某一种情况,那么就用那个矩阵来表示这个像素。比如灰度是 0, 那么那个像素就用图中 0 的情况的矩阵表示。

程序实现不难,不多说直接上代码吧:

%%
clear all;
clc;
close all; %% 生成一个大小为 256 *256 的简便灰度图像
s = 256;
y = zeros(s,s);
% 每行对应一个灰度级
for (i=1:s)
y(i,:)=(255-i-1)*ones(1,s);
end
y=uint8(y);
imwrite(y,'general_img.jpg'); %% 基于半色调计数的图像打印程序
% x = imread('general_img.jpg'); %读取图片
x = imread('gray_image.jpg'); %读取图片 figure(1)
imshow(x);
title('original_image'); [r, c] = size(x); % 获取图片大小 % 判断图片大小是否超过 272 * 352, 若超过则进行调整
r_scale = double(r) / 272;
c_scale = double(c) / 352; scale = max(r_scale, c_scale); % 找出较大的,后面进行压缩 % 若图像过大,进行压缩
if(scale > 1)
x = imresize(x, 1.0 / scale );
imwrite(x, 'adjusted_img.jpg');
end figure(2)
imshow(x);
title('adjusted_image'); %% 将256灰度级量化成10灰度级别
[ry, cy] = size(x); % 获取图片大小
qim = fix( double(x) / 25.6 ); % 四舍五入。灰度级减小到10灰度级,取整数形式。
y = zeros(ry*3, cy*3); % 创建新图片 % 构造点模式表示10个灰度级
dot_mat(:,:,1)=zeros(3,3);
dot_mat(:,:,2)=[0 255 0;0 0 0;0 0 0];
dot_mat(:,:,3)=[0 255 0;0 0 0;0 0 255];
dot_mat(:,:,4)=[255 255 0;0 0 0;0 0 255];
dot_mat(:,:,5)=[255 255 0;0 0 0;255 0 255];
dot_mat(:,:,6)=[255 255 255;0 0 0,;255 0 255];
dot_mat(:,:,7)=[255 255 255;0 0 255,;255 0 255];
dot_mat(:,:,8)=[255 255 255;0 0 255;255 255 255];
dot_mat(:,:,9)=[255 255 255;255 0 255;255 255 255];
dot_mat(:,:,10)=[255 255 255;255 255 255;255 255 255]; % 对每个图像进行点阵映射
for (i = 1:ry)
for (j = 1:cy)
level = qim(i, j); % 去除灰度级
y((i-1)*3+1:i*3,(j-1)*3+1:j*3)=dot_mat(:,:,level+1);
end
end y = uint8(y); figure(3)
imshow(y);
title('halftoning'); imwrite(y,'halftoning.jpg');

实验结果:

第一张图片是原图像;

第二张图片是调整大小后的图像,由于使用半色调技术会将原图像放大,所以事先将图片大小缩小一些,避免使用半色调技术后生成的图像过大;

第三张图片就是结果, 也可以在当前文件夹目录下查看程序生成的halftoning.jpg图片。

数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Halftoning 标签: 图像处理MATLAB 2017-04-2的更多相关文章

  1. 数字图像处理实验(总计23个)汇总 标签: 图像处理MATLAB 2017-05-31 10:30 175人阅读 评论(0)

    以下这些实验中的代码全部是我自己编写调试通过的,到此,最后进行一下汇总. 数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Half ...

  2. 数字图像处理实验(12):PROJECT 05-03,Periodic Noise Reduction Using a Notch Filter 标签: 图像处理MATLAB 2017-0

    实验要求: Objective: To understand the principle of the notch filter and its periodic noise reducing abi ...

  3. http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html

    http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html

  4. oracle问题 《经由直接路径由 EXPORT:V10.02.01 创建的导出文件 IMP-00013: 只有 DBA 才能导入由其他 DBA 导出的文件》

    问题:  经由直接路径由 EXPORT:V10.02.01 创建的导出文件 : 只有 DBA 才能导入由其他 DBA 导出的文件 解决方法:用sys 登录,给当前用户授权,授权语句:grant dba ...

  5. 2016.02.01日,UdoOS系统项目正式开通了

    2016.02.01日,UdoOS系统项目正式开通了,源代码即将开放 Copyright (c) 2016

  6. 02.02.01 第1章 简介及基础操作(Power BI商业智能分析)

    02.02.01.01 powerbi简介 00:10:59 02.02.01.02 query数据导入 00:03:26 具体操作实例如下: 02.02.01.03导入access数据 00:05: ...

  7. http://www.cnblogs.com/langtianya/archive/2013/02/01/2889682.html

    http://www.cnblogs.com/langtianya/archive/2013/02/01/2889682.html

  8. 042 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 04 案例演示while循环的使用——循环输出英文字母

    042 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 04 案例演示while循环的使用--循环输出英文字母 本文知识点:案例演示while循环的使用2 ...

  9. 数字图像处理实验(16):PROJECT 06-03,Color Image Enhancement by Histogram Processing 标签: 图像处理MATLAB 2017

    实验要求: Objective: To know how to implement image enhancement for color images by histogram processing ...

随机推荐

  1. datatable绑定comboBox,在下拉菜单中显示对应数据

    实现功能: datatable绑定comboBox,在下拉菜单中显示对应数据 实现方法: .生成datatable,并为combox绑定数据源: comboBox1.DataSource = dt1; ...

  2. 20165210 Java第九周学习总结

    20165210 Java第九周学习总结 教材学习内容 - 第十三章学习总结 URL类: URL的构造方法: try { URL url = new URL("http://www.goog ...

  3. BestCoder Round #18(hdu5105)Math Problem(高中数学)

    最大值无非就是在两个端点或极值点处取得. 我注意讨论了a=0和b=0,却忽略了极值点可能不在L到R的范围内这一问题.被Hack了. #include<iostream> #include& ...

  4. visual assist(VA)设置快捷键(其它安装的插件设置快捷键也在这里)

    安装完visual assist后发现快捷键无法使用纠结,然后找如何去设置快捷建以此记录一下: 在Tools-->customize-->Keyboard-->Add-ins 常用的 ...

  5. ACM学习历程—Hihocoder 1139 二分·二分答案(bfs)

    http://hihocoder.com/problemset/problem/1139 这题提示上写的是二分,但是感觉不二分应该也可以,至少题目是AC的... 二分的思想就是二分答案的值,看能不能在 ...

  6. MA82G5D16AS16 主频调试记录

    MA82G5D16AS16 主频调试记录 当 SCKS 设置 为 MCKDO / 128 时 MCU 的电流为 0.58mA,100UF 电容可以维持 0.5S,大概可以满足. 但是需要注意外围的线路 ...

  7. Java程序员如何在竞争中保持优势

    Java程序员入门容易,进阶很难,想要在竞争中保持优势,脚踏实地的同时也要仰望星空规划自己的未来.时间在流逝,年龄在增加,你期望的薪水也在不断增多,你总得让自己能力持续增加以配得上想要的收入吧. 从初 ...

  8. java中io的详解

    注:本文全篇转载于:http://blog.csdn.net/taxueyingmei/article/details/7697042,觉得讲的挺详细,就借过来看看,挺不错的文章. 先贴一张图 Jav ...

  9. TLD视觉跟踪算法

    TLD算法好牛逼一个,这里有个视频,是作者展示算法的效果,http://www.56.com/u83/v_NTk3Mzc1NTI.html.下面这个csdn博客里有人做的相关总结,感觉挺好的,收藏了! ...

  10. MongoDb学习网站

    http://www.runoob.com/mongodb/mongodb-window-install.html