MATLAB 中的直方图均衡帮助
Histogram equalization help in MATLAB
我的代码如下所示:
G= histeq(imread('F:\Thesis\images\image1.tif'));
figure,imshow(G);
我收到的错误消息如下,我不确定为什么会出现:
Error using histeq
Expected input number 1, I, to be two-dimensional.
Error in histeq (line 68)
validateattributes(a,{'uint8','uint16','double','int16','single'}, ...
Error in testFile1 (line 8)
G= histeq(imread('F:\Thesis\images\image1.tif'));
您的图片很可能是彩色的。 histeq
仅适用于灰度图像。根据您要执行的操作,您可以使用三个选项。您可以将图像转换为灰度,可以分别对每个通道进行直方图均衡,或者在感知上更好的方法是将图像转换为 HSV 颜色 space,直方图对 V 或值分量进行均衡,然后再转换回 RGB。对于彩色图像,我倾向于选择最后一个选项。因此,一种方法将是增强的灰度图像,另外两种将是增强的彩色图像。
选项 #1 - 转换为灰度然后均衡
G = imread('F:\Thesis\images\image1.tif');
G = histeq(rgb2gray(G));
figure; imshow(G);
使用rgb2gray
将图像转换为灰度,然后对图像进行均衡。
选项 #2 - 单独均衡每个通道
G = imread('F:\Thesis\images\image1.tif');
for i = 1 : size(G, 3)
G(:,:,i) = histeq(G(:,:,i));
end
figure; imshow(G);
遍历每个通道并均衡。
选项 #3 - 转换为 HSV,直方图均衡 V 通道然后转换回来
G = imread('F:\Thesis\images\images1.tif');
Gh = rgb2hsv(G);
Gh(:,:,3) = histeq(Gh(:,:,3));
G = im2uint8(hsv2rgb(Gh));
figure; imshow(G);
使用 rgb2hsv
function to convert a colour image into HSV. We then use histogram equalization on the V or Value channel, then convert back from HSV to RGB with hsv2rgb
. Note that the output of hsv2rgb
will be a double
type image and so assuming that the original input image was uint8
, use the im2uint8
函数将 double
转换回 uint8
。
我的代码如下所示:
G= histeq(imread('F:\Thesis\images\image1.tif'));
figure,imshow(G);
我收到的错误消息如下,我不确定为什么会出现:
Error using histeq
Expected input number 1, I, to be two-dimensional.
Error in histeq (line 68)
validateattributes(a,{'uint8','uint16','double','int16','single'}, ...
Error in testFile1 (line 8)
G= histeq(imread('F:\Thesis\images\image1.tif'));
您的图片很可能是彩色的。 histeq
仅适用于灰度图像。根据您要执行的操作,您可以使用三个选项。您可以将图像转换为灰度,可以分别对每个通道进行直方图均衡,或者在感知上更好的方法是将图像转换为 HSV 颜色 space,直方图对 V 或值分量进行均衡,然后再转换回 RGB。对于彩色图像,我倾向于选择最后一个选项。因此,一种方法将是增强的灰度图像,另外两种将是增强的彩色图像。
选项 #1 - 转换为灰度然后均衡
G = imread('F:\Thesis\images\image1.tif');
G = histeq(rgb2gray(G));
figure; imshow(G);
使用rgb2gray
将图像转换为灰度,然后对图像进行均衡。
选项 #2 - 单独均衡每个通道
G = imread('F:\Thesis\images\image1.tif');
for i = 1 : size(G, 3)
G(:,:,i) = histeq(G(:,:,i));
end
figure; imshow(G);
遍历每个通道并均衡。
选项 #3 - 转换为 HSV,直方图均衡 V 通道然后转换回来
G = imread('F:\Thesis\images\images1.tif');
Gh = rgb2hsv(G);
Gh(:,:,3) = histeq(Gh(:,:,3));
G = im2uint8(hsv2rgb(Gh));
figure; imshow(G);
使用 rgb2hsv
function to convert a colour image into HSV. We then use histogram equalization on the V or Value channel, then convert back from HSV to RGB with hsv2rgb
. Note that the output of hsv2rgb
will be a double
type image and so assuming that the original input image was uint8
, use the im2uint8
函数将 double
转换回 uint8
。