数字图像处理实验(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. Note that the definition of histogram for color images differs from that of histogram for gray images.
Main requirements:
Ability of programming with C, C++, or Matlab.
Instruction manual:
(a) Download the dark-stream color picture in Fig. 6.35 (this image is labeled Fig. 6.35(05) in the image gallery for Chapter 6). Convert the image to RGB (see comments at the beginning of Project 06-01). Histogram-equalize the R, G, and B images separately using the histogram-equalization program and convert the image back to jpg format.
(b) Form an average histogram from the three histograms in (a) and use it as the basis to obtain a single histogram equalization intensity transformation function. Apply this function to the R, G, and B components individually, and convert the results to jpg. Compare and explain the differences in the jpg images in (a) and (b).
本实验是对彩色图像进行直方图均衡化处理。其中,我分了两种方式对彩色图像进行处理。一种是对图像的R、G、B三个彩色分量进行直方图均衡化,另一种是将图像从RGB颜色空间转换到HSI颜色空间,使用直方图均衡化单独处理亮度I分量,随后将图像从HSI空间转换回到RGB颜色空间。对比两种处理方法的结果。
实验代码:
%%
close all;
clc;
clear all;
%%
img = imread('Fig6.35(5).jpg');
figure
subplot(1,3,1);
imshow(img);
title('original image');
%% 对RGB3个通道的灰度值分别做直方图均衡化,然后再合为一幅新的图像
R = img(:, :, 1);
G = img(:, :, 2);
B = img(:, :, 3);
A = histeq(R);
B = histeq(G);
C = histeq(B);
img1 = cat(3, A, B, C);
subplot(1,3,2);
imshow(img1);
title('histogram-equalization 1');
%% 先将RGB格式的图像转换为HSI格式的图像,然后再对亮度I做直方图均衡化,紧接着转换成RGB格式的图像
img_hsi = rgb2hsi(img);
img_hsi_i = img_hsi(:, :, 3);
img_hsi_I = histeq(img_hsi_i);
img_hsi(:, :, 3) = img_hsi_I;
img2 = hsi2rgb(img_hsi);
subplot(1,3,3);
imshow(img2);
title('histogram-equalization 2');
补充:
程序中使用的一些函数,RGB和HSI颜色空间之间相互转换的程序:
hsi2rgb()函数:
function rgb = hsi2rgb(hsi)
%HSI2RGB Converts an HSI image to RGB.
% RGB = HSI2RGB(HSI) converts an HSI image to RGB, where HSI is
% assumed to be of class double with:
% hsi(:, :, 1) = hue image, assumed to be in the range
% [0, 1] by having been divided by 2*pi.
% hsi(:, :, 2) = saturation image, in the range [0, 1].
% hsi(:, :, 3) = intensity image, in the range [0, 1].
%
% The components of the output image are:
% rgb(:, :, 1) = red.
% rgb(:, :, 2) = green.
% rgb(:, :, 3) = blue.
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.5 $ $Date: 2003/10/13 01:01:06 $
% Extract the individual HSI component images.
H = hsi(:, :, 1) * 2 * pi;
S = hsi(:, :, 2);
I = hsi(:, :, 3);
% Implement the conversion equations.
R = zeros(size(hsi, 1), size(hsi, 2));
G = zeros(size(hsi, 1), size(hsi, 2));
B = zeros(size(hsi, 1), size(hsi, 2));
% RG sector (0 <= H < 2*pi/3).
idx = find( (0 <= H) & (H < 2*pi/3));
B(idx) = I(idx) .* (1 - S(idx));
R(idx) = I(idx) .* (1 + S(idx) .* cos(H(idx)) ./ ...
cos(pi/3 - H(idx)));
G(idx) = 3*I(idx) - (R(idx) + B(idx));
% BG sector (2*pi/3 <= H < 4*pi/3).
idx = find( (2*pi/3 <= H) & (H < 4*pi/3) );
R(idx) = I(idx) .* (1 - S(idx));
G(idx) = I(idx) .* (1 + S(idx) .* cos(H(idx) - 2*pi/3) ./ ...
cos(pi - H(idx)));
B(idx) = 3*I(idx) - (R(idx) + G(idx));
% BR sector.
idx = find( (4*pi/3 <= H) & (H <= 2*pi));
G(idx) = I(idx) .* (1 - S(idx));
B(idx) = I(idx) .* (1 + S(idx) .* cos(H(idx) - 4*pi/3) ./ ...
cos(5*pi/3 - H(idx)));
R(idx) = 3*I(idx) - (G(idx) + B(idx));
% Combine all three results into an RGB image. Clip to [0, 1] to
% compensate for floating-point arithmetic rounding effects.
rgb = cat(3, R, G, B);
rgb = max(min(rgb, 1), 0);
rgb2hsi()函数:
function hsi = rgb2hsi(rgb)
%RGB2HSI Converts an RGB image to HSI.
% HSI = RGB2HSI(RGB) converts an RGB image to HSI. The input image
% is assumed to be of size M-by-N-by-3, where the third dimension
% accounts for three image planes: red, green, and blue, in that
% order. If all RGB component images are equal, the HSI conversion
% is undefined. The input image can be of class double (with values
% in the range [0, 1]), uint8, or uint16.
%
% The output image, HSI, is of class double, where:
% hsi(:, :, 1) = hue image normalized to the range [0, 1] by
% dividing all angle values by 2*pi.
% hsi(:, :, 2) = saturation image, in the range [0, 1].
% hsi(:, :, 3) = intensity image, in the range [0, 1].
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.5 $ $Date: 2005/01/18 13:44:59 $
% Extract the individual component images.
rgb = im2double(rgb);
r = rgb(:, :, 1);
g = rgb(:, :, 2);
b = rgb(:, :, 3);
% Implement the conversion equations.
num = 0.5*((r - g) + (r - b));
den = sqrt((r - g).^2 + (r - b).*(g - b));
theta = acos(num./(den + eps));
H = theta;
H(b > g) = 2*pi - H(b > g);
H = H/(2*pi);
num = min(min(r, g), b);
den = r + g + b;
den(den == 0) = eps;
S = 1 - 3.* num./den;
H(S == 0) = 0;
I = (r + g + b)/3;
% Combine all three results into an hsi image.
hsi = cat(3, H, S, I);
程序运行结果:
数字图像处理实验(16):PROJECT 06-03,Color Image Enhancement by Histogram Processing 标签: 图像处理MATLAB 2017的更多相关文章
- 数字图像处理实验(总计23个)汇总 标签: 图像处理MATLAB 2017-05-31 10:30 175人阅读 评论(0)
以下这些实验中的代码全部是我自己编写调试通过的,到此,最后进行一下汇总. 数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Half ...
- Win8Metro(C#)数字图像处理--2.16图像浮雕效果
原文:Win8Metro(C#)数字图像处理--2.16图像浮雕效果 [函数名称] 图像浮雕效果函数ReliefProcess(WriteableBitmap src) [函数代码] ...
- 数字图像处理实验(5):Proj03-01 ~ Proj03-06 标签: 图像处理matlab 2017-04-30 10:39 184人阅读
PROJECT 03-01 : Image Enhancement Using Intensity Transformations 实验要求: Objective To manipulate a te ...
- android 1.6 launcher研究之自定义ViewGroup (转 2011.06.03(二)——— android 1.6 launcher研究之自定义ViewGroup )
2011.06.03(2)——— android 1.6 launcher研究之自定义ViewGroup2011.06.03(2)——— android 1.6 launcher研究之自定义ViewG ...
- 数字图像处理实验(17):PROJECT 06-04,Color Image Segmentation 标签: 图像处理MATLAB 2017-05-27 21:13
实验报告: Objective: Color image segmentation is a big issue in image processing. This students need to ...
- 数字图像处理实验(14):PROJECT 06-01,Web-Safe Colors 标签: 图像处理MATLAB 2017-05-27 20:45 116人阅读
实验要求: Objective: To know what are Web-safe colors, how to generate the RGB components for a given jp ...
- 数字图像处理实验(10):PROJECT 05-01 [Multiple Uses],Noise Generators 标签: 图像处理MATLAB 2017-05-26 23:36
实验要求: Objective: To know how to generate noise images with different probability density functions ( ...
- 数字图像处理实验(15):PROJECT 06-02,Pseudo-Color Image Processing 标签: 图像处理MATLAB 2017-05-27 20:53
实验要求: 上面的实验要求中Objective(实验目的)部分是错误的. 然而在我拿到的大纲中就是这么写的,所以请忽视那部分,其余部分是没有问题的. 本实验是使用伪彩色强调突出我们感兴趣的灰度范围,在 ...
- 数字图像处理实验(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 ...
随机推荐
- Oracle查询多边形对象SDO_GEOMETRY并转换为java对象举例
最近实现了一个判断点是否与多边形交互的功能,这里的点是一个经纬度,多边形是一个区域,包含多个经纬度,最后看下这个点是否在这个区域内.就好比你打开百度地图,然后看你自己的位置(点)是不是在某个小区(多边 ...
- juc线程池原理(二):ThreadPoolExecutor的成员变量介绍
概要 线程池的实现类是ThreadPoolExecutor类.本章,我们通过分析ThreadPoolExecutor类,来了解线程池的原理. ThreadPoolExecutor数据结构 Thread ...
- python开发模块基础:异常处理&hashlib&logging&configparser
一,异常处理 # 异常处理代码 try: f = open('file', 'w') except ValueError: print('请输入一个数字') except Exception as e ...
- 八 Connect API 连接器
Connect API: 实现一个连接器(connector),不断地从一些数据源系统拉取数据到kafka,或从kafka推送到宿系统(sink system). 大多数Connect使用者不需要直接 ...
- JavaScript笔记——事件
事件一般是用于浏览器和用户操作进行交互.最早是 IE 和 Netscape Navigator 中出现, 作为分担服务器端运算负载的一种手段.直到几乎所有的浏览器都支持事件处理.而 DOM2 级规范开 ...
- Angular2快速入门-3.多个组件(分离新闻列表页和详细页)
上篇(Angular2快速入门-2.创建一个新闻列表)已经完成新闻列表的展示,并且点击新闻列表的时候,下面可以展示出新闻的详细信息,这节我们把新闻详细和新闻列表页面分离出来 新闻详细单独一个compo ...
- PHP函数(四)-变量函数
变量函数 将声明的函数的函数名赋给一个变量,通过该变量来调用函数 <?php function Calculate($a,$b){ return $a + $b; } echo "计算 ...
- Python Twisted系列教程11:改进诗歌下载服务器
作者:dave@http://krondo.com/your-poetry-is-served/ 译者:杨晓伟(采用意译) 你可以从这里从头阅读这个系列. 诗歌下载服务器 到目前为止,我们已经学习了大 ...
- Centos7 超简单将Centos的yum源更换为国内的阿里云源
1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.下载新的CentOS-Base ...
- Unable to correct problems, you have held broken package
其实这篇接着上文(一),主要是解决samba安装的问题,中间又是一路曲折.不过这个问题也算是比较典型,有必要记录一下. #apt-get install smb* 安装失败.其实顺利的话,直接一条这样 ...