日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数字图像处理实验(16):PROJECT 06-03,Color Image Enhancement by Histogram Processing

發布時間:2025/3/21 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数字图像处理实验(16):PROJECT 06-03,Color Image Enhancement by Histogram Processing 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實驗要求:

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。