【问题标题】:MATLAB Histogram equalization on GIF imagesGIF 图像上的 MATLAB 直方图均衡化
【发布时间】:2013-09-22 15:01:26
【问题描述】:

在对图像执行直方图均衡后,我很难理解如何更改灰度 GIF 图像的颜色图。对于没有关联颜色图的图像压缩类型(例如 JPEG),该过程非常简单,而且我已经将它用于处理灰度 JPEG 图像。

clear
clc
[I,map] = imread('moon.gif');
h = zeros(256,1);    %array value holds number of pixels with same value
hmap = zeros(256,1);
P = zeros(256,1);    %probability that pixel intensity will appear in image
Pmap = zeros(256,1);
s = zeros(256,1);    %calculated CDF using P
smap = zeros(256,1);
M = size(I,1);
N = size(I,2);
I = double(I);

Inew = double(zeros(M,N));
mapnew = zeros(256,3);
for x = 1:M;
for y = 1:N;
for l = 1:256;
    %count pixel intensities and probability 
end
end
end

for j = 2:256
    for i = 2:j
        %calculate CDF of P
    end
end
s(1) = P(1);
smap(1) = Pmap(1);

for x = 1:M;
for y = 1:N;
for l = 1:256;
   %calculates adjusted CDF and sets it to new image
end
end
end
mapnew = mapnew/256;
Inew = uint8(Inew);
I = uint8(I);
subplot(1,2,1), imshow(Inew,map);     %comparing the difference between original map 
subplot(1,2,2), imshow(Inew,mapnew);  %to'enhanced' colormap, but both turn out poorly

就实际图像的均衡而言,一切都很好,但我不确定要对颜色图进行哪些更改。我尝试在颜色图上执行与图像相同的操作,但没有骰子。

很抱歉,由于我的声望低,我无法发布图片,但我会尽力根据要求提供所有信息。

任何帮助将不胜感激。

【问题讨论】:

  • 建议:您可以在imgur上传图片并发布链接。更有特权的用户可以为您将它们嵌入到您的问题中,直到您获得自己这样做的声誉......欢迎来到 SO!
  • 如果你让它适用于常规图像(灰度或真彩色),你总是可以使用ind2grayind2rgb 将图像及其对应的颜色图转换为第一种,然后执行你的程序。 fwiw MATLAB 已经有 histeq 函数适用于所有类型的图像
  • 感谢大家的帮助! ind2gray 函数就像一个魅力。这是一个课堂作业,所以 histeq 是不可能的,保存以确保您的代码正常工作。我还会记住使用 imgur 来提供图像。再次感谢您的帮助。

标签: matlab image-processing histogram color-mapping


【解决方案1】:
function J=histeqo(I)

    J=I;
    [m,n]=size(I);
    [h,d]=imhist(I);
    ch=cumsum(h);  // The cumulative frequency
    imagesize=(m*n); // The image size lightsize=size(d,1);// The Lighting range
    tr=ch*(lightsize/imagesize); // Adjustment function

    for x=1:m
        for y=1:n
            J(x,y)=tr(I(x,y)+1);
        end
    end
    subplot(1,2,1);imshow(J);
    subplot(1,2,2);imhist(J);
end

【讨论】:

  • 欢迎来到 SO 并感谢您的回答。请注意,这是一个英语网站。您能否编辑您的答案以包含仅英语的 cmets?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
  • 2013-11-20
  • 2010-12-23
  • 2020-02-11
  • 2018-04-28
  • 2013-01-25
相关资源
最近更新 更多