直方图规定化 直方图规定化步骤

2025-05-01 18:58 - 立有生活网

matlab histeq函数做直方图规定化

建议用默认的参数就可以。

对于double型图像,hgram的各元素值域为[0,1];而对于uint8型图像,hgram的各元素的取值范围为[0,255]。J=histeq(I,n)指定直方图化后的灰度等级数n,默认值为64。

直方图规定化 直方图规定化步骤直方图规定化 直方图规定化步骤


直方图规定化 直方图规定化步骤


直方图规定化 直方图规定化步骤


例 给出直方图均衡化增强图像对比度的MATLAB 程序。

I=imread('lena.bmp');

J=histeq(I);%对原图像进行直方图均衡化处理

imshow(I);title('原图像');

figure,imshow(J);

figure,subplot(1,2,1);

imhist(I,64);title('原图像');

subplot(1,2,2);

imhist(J,64);title('均衡化之后的图像')

I=imread('loufang.jpg');

subplot(141),imshow(I);

title('原始图像');

hgram=50:1:; %规定化函数

J=histeq(I,hgram);

subplot(142),imshow(J);

title('直方图规定化后的图像');

subplot(143),imhist(I,64);

title('原始图像的直方图');

subplot(144),imhisfor l = linit:N % 规定直方图从上一次最小处计算,节省运算时间t(J,64);

title('直方图规定化后的直方图');

%运行结果:

%变换灰度间隔后的图像和直方图:

%hgram=50:1:; hgram=50:5:;

如何用Matlab实现直方图规定化

break;

程序在这边,就不贴实验了

linit = 2;

clear all

close all

f= imread('2.jpg');

I=double(f); [m,n]=size(I);

H=zeros(1,256);

for i=1:m

for j=1:n

H(I(i,j)+1)=H(I(i,j)+1)+1; %求各灰度级的像素数

end

end

s=zeros(1,256);t=zeros(1,256);

for i=1:256

s(i)=H(i)/(mn); %求各灰度级的频率

% for j=1:i

% t(i)=t(i)+s(j); %求累计频率的和

%end

end

% 原始直方图的累积直方图

histc = cumsum(s);

% 规定直方图的累积直方图

matchhist=g/(mn);

matchhistc = cumsum(matchhist);

N = length(matchhist);

tk = zeros(1,M); % 映射关系hist-->tk

%if strcmp(mapl,'SML') 以下为单映射规则(‘SML’)

tk(1) = 1;

kinit = 0;

for k = 1:M %删除histc(k)=0的单元

if histc(k) == 0

kinit = kinit + 1;

else

end

end

% 标记为SML为零的位置

indis0 = zeros(1,N);

% 为节省运算量而修改

if matchhistc(l) == matchhistc(l - 1); %去掉相等为0的单元

continue;

end

if mappingL(l) == 0

end

end

mappingL(N) = abs(histc(k) - matchhistc(N));

indtemp2 = find(indis0 == 1);

[minmap,tk(k)] = min(mappingL(linit:N));

linit = tk(k) + linit - 1;

end

end

if N < M

for k = N:M

tk(k) = N;

end

end

histm = zeros(1,N);

end

tk = tk - 1; % 方便灰度值的计算

% 图像的规定化

for p = 1:size(f,1)

for q = 1:size(f,2)

ind = f(p,q) + 1;

imagematch(p,q) = tk(ind);

end

end

subplot(321)

title('原始图像')

subplot(322)

imshow(imagematch)

title('直方图规定化后图像')

subplot(323)

bar(H,'g');

xlabel('灰度值')

ylabel('统计个数');

title('原始直方图')

bar(histm,'g');

xlabel('灰度值')

ylabel('统计个数');

title(['规定化后直方图'])

subplot(3,2,5),a=rgb2gray(f);g=histeq(a,matchhist);imshow(g);title('图像的规定化');

subplot(3,2,6),a=rgb2gray(f);g=histeq(a,matchhist);h=imhist(g);plot(h),title('图像的规定化直方图');

怎样用matlab对一幅图像进行灰度直方图规定化处理

%%用的是单映射规则(‘SML’ )

clear all

close all

f= imread('2.jpg');

I=double(f); [m,n]=size(I);

H=zeros(1,256);

for i=1:m

for j=1:n

H(I(i,j)+1)=H(I(i,j)+1)+1; %求各灰度级的像素数

end

end

s=zeros(1,256);t=zeros(1,256);

for i=1:256

s(i)=H(i)/(mn); %求各灰度级的频率

% for j=1:i

% t(i% 映射的实现)=t(i)+s(j); %求累计频率的和

%end

end

% 原始直方图的累积直方图

histc = cumsum(s);

% 规定直方图的累积直方图

matchhist=g/(mn);

matchhistc = cumsum(matchhist);

N =linit = 2; length(matchhist);

tk = zeros(1,M); % 映射关系hist-->tk

%if strcmp(mapl,'SML') 以下为单映射规则(‘SML’)

tk(1) = 1;

kinit = 0;

for k = 1:M %删除histc(k)=0的单元

if histc(k) == 0

kinit = kinit + 1;

else

end

end

% 标记为SML为零的位置

indis0 = zeros(1,N);

% 为节省运算量而修改

if matchhistc(l) == matchhistc(l - 1); %去掉相等为0的单元

continue;

end

if mappingL(l) == 0

end

end

mappingL(N) = abs(histc(k) - matchhistc(N));

indtemp2 = find(indis0 == 1);

[minmap,tk(k)] = min(mappingL(linit:N));

linit = tk(k) + linit - 1;

end

end

if N < M

for k = N:M

tk(k) = N;

end

end

histm = zeros(1,N);

end

tk = tk - 1; % 方便灰度值的计算

% 图像的规定化

for p = 1:size(f,1)

for q = 1:size(f,2)

ind = f(p,q) + 1;

imagematch(p,q) = tk(ind);

end

end

subplot(321)

title('原始图像')

subplot(322)

imshow(imagematch)

title('直方图规定化后图像')

subplot(323)

bar(H,'g');

xlabel('灰度值')

ylabel('统计个数');

title('原始直方图')

bar(histm,'g');

xlabel('灰度值')

ylabel('统计个数');

title(['规定化后直方图'])

subplot(3,2,5),a=rgb2gray(f);g=histeq(a,matchhist);imshow(g);title('图像的规定化');

subplot(3,2,6),a=rgb2gray(f);g=histeq(a,matchhist);h=imhist(g);plot(h),title('图像的规定化直方图');

怎样用matlab对一幅图像进行灰度直方图规定化处理

%%用的是单映射规则(‘SML’ )

clear all

close all

f= imread('2.jpg')for k = 1:M;

I=double(f); [m,n]=size(I);

H=zeros(1,256);

for i=1:m

for j=1:n

H(I(i,j)+1)=H(I(i,j)+1)+1; %求各灰度级的像素数

end

end

s=zeros(1,256);t=zeros(1,256);

for i=1:256

s(i)=H(i)/(mn); %求各灰度级的频率

% for j=1:i

% t(i)=t(i)+s(j); %求累计频率的和

%end

end

% 原始直方图的累积直方图

histc = cumsum(s);

% 规定直方图的累积直方图

matchhist=g/(mn);

matchhistc = cumsum(matchhist);

N = length(matchhist);

tk = zeros(1,M); % 映射关系hist-->tk

%if strcmp(mapl,'SML') 以下为单映射规则(‘SML’)

tk(1) = 1;

kinit = 0;

for k = 1:M %删除histc(k)=0的单元

if histc(k) == 0

kinit = kinit + 1;

else

end

end

% 标记为SML为零的位置

indis0 = zeros(1,N);

% 为节省运算量而修改

if matchhistc(l) == matchhistc(l - 1); %去掉相等为0的单元

continue;

end

if mappingL(l) == 0

end

end

mappingL(N) = abs(histc(k) - matchhistc(N));

indtemp2 = find(indis0 == 1);

[minmap,tk(k)] = min(mappingL(linit:N));

linit = tk(k) + linit - 1;

end

end

if N < M

for k = N:M

tk(k) = N;

end

end

histm = zeros(1,N);

end

tk = tk - 1; % 方便灰度值的计算

% 图像的规定化

for p = 1:size(f,1)

for q = 1:size(f,2)

ind = f(p,q) + 1;

imagematch(p,q) = tk(ind);

end

end

subplot(321)

title('原始图像')

subplot(322)

imshow(imagematch)

title('直方图规定化后图像')

subplot(323)

bar(H,'g');

xlabmappingL = zeros(size(matchhist));el('灰度值')

ylabel('统计个数');

title('原始直方图')

bar(histm,'g');

xlabel('灰度值')

ylabel('统计个数');

title(['规定化后直方图'])

subplot(3,2,5),a=rgb2gray(f);g=histeq(a,matchhist);imshow(g);title('图像的规定化');

subplot(3,2,6),a=rgb2gray(f);g=histeq(a,matchhist);h=imhist(g);plot(h),title('图像的规定化直方图');

matlab histeq函数做直方图规定化

对于double型图像,hgram的各元素值域为[0,1];而对于uint8型图像,hgram的各元素的取值范围为[0,255]。J=histeq(I,n)指定直方图化后的灰度等级数n,默认值为64。

例 给出直方图均衡化增强图像对比度的MATLAB 程序。

I=imread('lena.bmp');

J=histeq(I);%对原图像进行直方%下面利用直方图规定化对图像进行增强:图均衡化处理

imindtemp1 = find(mappingL == 0);show(I);title('原图像');

figure,imshow(J);

figure,subplot(1,2,1);

imhist(I,64);title('原图像');

subplot(1,2,2);

imhist(J,64);title('均衡化之后的图像')

I=imread('loufang.jpg');

subplot(141),imshow(I);

title('原始图像');

hgram=50:1:; %规定化函数

J=histeq(I,hgram);

subplot(142),imshow(J);

title('直方图规定化后的图像');

subplot(143),imhist(I,64);

title('原始图像的直方图');

subplot(144),imhist(J,64);

title('直方图规定化后的直方图');

%运行结果:

%变换灰度间隔后的图像和直方图:

%hgram=50:1:; hgram=50:5:;

直方图均衡化对有些不能达到好的效果, 为什么?

histm(tk(k)) = histm(tk(k)) + H(k);

直方图均衡化基本上是对一幅图中的灰度值进行一下重排列平均分布一下 如果你的原始图像里面没有亮的部分全部是黑暗的灰度值接近0或者很低灰度值的 当然是不会有好效果的 就是你说的特别暗的图像 本身它的灰度值都集中在100以下 你就算是均匀分布这些低灰度值的象素 得到的还是低灰度值的 的一片黑暗 特别是 看你写的公式 你在用matlab做这个程序吧 matlab处理都是按照矩阵 方块处理 会出现马赛克小块 一般的 处理这种问题可以自己稍微制造一些亮块 或者是 暗块来方便均匀化后的效果 得到各个亮度的点的总和以后 选择最多的那个值 比如说一个暗色的图 hist=80 有6000个点 那么就把灰度值=80×0.9 (记住去floor) 以上的 全部+20-40 变亮整个图像 或者自己写一个function 来检测拿125为检测界限

如果有需indis0(linit) = 1;求 可以发你需要处理的 效果不好的 给我 我用matlab 试试看

lanceinmf@yahoo

matlab直方图规定化

imshow(f)

均衡化是变换原始图象的直方图为均匀分布,使像素灰度值的动态范围,增强图象整体对比度(反);直方图规定化是借助直方图变换实现规定/特定的灰度映射,使得变换后的直方图近似于事先给定的分布。这是两个不同目的的作,根据需要进行选择,如果只是要增强反用均衡化就够了。matlab中有histeq函数可以进行以上作,可参考:

mappingL(setdiff(indtemp1,indtemp2)) = inf;

histeq - Enhance contrast using histogram equalization

This MATLAB function transforms the intensity image I so that the histogram of

the output intensity image J with length(hgram) bins approximay matches

hgram.

J = histeq(I,hgram)

J = histeq(I,n)

[J, T] = histeq(I)

[gpuarrayJ, gpuarrayT] = histeq(gpuarrayI,___)

newmap = histeq(X, map, hgram)

newmap = histeq(X, map)

[newmap, T] = histeq(X,___)

均衡化是让灰度分布变平均,规定化是让它近似某个特定分布。

望采纳,谢谢!

均衡化是使的各灰度出现的概率大致一样

而规定化是使直方图大致趋于你给定的一个函数

matlab直方图规定化

imagematch = zeros(size(f));

均衡化是变换原始图象的直方图为均匀分布,使像素灰度值的动态范围,增强图象整体对比度(反);直方图规定化是借助直方图变换实现规定/特定的灰度映射,使得变换后的直方图近似于事先给定的分布。这是两个不同目的的作,根据需要进行选择,如果只是要增强反用均衡化就够了。matlab中有histeq函数可以进行以上作,可参考:

histeq - Enhance contrast using histogram equalization

This MATLAB function transforms the intensity image I so that the histogram of

the output intensity image J with length(hgram) bins approximay matches

hgram.

J = histeq(I,hgram)

J = histeq(I,n)

[J, T] = subplot(324)histeq(I)

[gpuarrayJ, gpuarrayT] = histeq(gpuarrayI,___)

newmap = histeq(X, map, hgram)

newmap = histeq(X, map)

[newmap, T] = histeq(X,___)

均衡化是让灰度分布变平均,规定化是让它近似某个特定分布。

望采纳,谢谢!

均衡化是使的各灰度出现的概率大致一样

而规定化是使直方图大致趋于你给定的一个函数

如何用Matlab实现直方图规定化

tk(k) = linit;

程序在这边,就不贴实验了

for k = kinit:M

clear all

close all

f= imread('2.jpg');

I=double(f); [m,n]=size(I);

H=zeros(1,256);

for i=1:m

for j=1:n

H(I(i,j)+1)=H(I(i,j)+1)+1; %求各灰度级的像素数

end

end

s=zeros(1,256);t=zeros(1,256);

for i=1:256

s(i)=H(i)/(mn); %求各灰度级的频率

% for j=1:i

% t(i)=t(i)+s(j); %求累计频率的和

%end

end

% 原始直方图的累积直方图

histc = cumsum(s);

% 规定直方图的累积直方图

matchhist=g/(mn);

matchhistc = cumsum(matchhist);

N = length(matchhist);

tk = zeros(1,M); % 映射关系hist-->tk

%if strcmp(mapl,'SML') 以下为单映射规则(‘SML’)

tk(1) = 1;

kinit = 0;

for k = 1:M %删除histc(k)=0的单元

if histc(k) == 0

kinit = kinit + 1;

else

end

end

% 标记为SML为零的位置

indis0 = zeros(1,N);

% 为节省运算量而修改

if matchhistc(l) == matchhistc(l - 1); %去掉相等为0的单元

continue;

end

if mappingL(l) == 0

end

end

mappingL(N) = abs(histc(k) - matchhistc(N));

indtemp2 = find(indis0 == 1);

[minmap,tk(k)] = min(mappingL(linit:N));

linit = tk(k) + linit - 1;

end

end

if N < M

for k = N:M

tk(k) = N;

end

end

histm = zeros(1,N);

end

tk = tk - 1; % 方便灰度值的计算

% 图像的规定化

for p = 1:size(f,1)

for q = 1:size(f,2)

ind = f(p,q) + 1;

imagematch(p,q) = tk(ind);

end

end

subplot(321)

title('原始图像')

subplot(322)

imshow(imagematch)

title('直方图规定化后图像')

subplot(323)

bar(H,'g');

xlabel('灰度值')

ylabel('统计个数');

title('原始直方图')

bar(histm,'g');

xlabel('灰度值')

ylabel('统计个数');

title(['规定化后直方图'])

subplot(3,2,5),a=rgb2gray(f);g=histeq(a,matchhist);imshow(g);title('图像的规定化');

subplot(3,2,6),a=rgb2gray(f);g=histeq(a,matchhist);h=imhist(g);plot(h),title('图像的规定化直方图');

关于直方图匹配的问题

M = double(intmax(class(f))) + 1;

(1)参考图像的直方图,通过变换,使两幅图像的亮度变化规律尽可能地接近;

tk(k) = tk(kinit);

(2)特定函数形式的直方图,通过变换,使变换后的图像亮度变化规律可能地服从这种函数的分布。

直方图规定化的原理:对两个直方图都做均衡化,变成相同的归一化的均匀直方图,以此均匀直方图为媒介,再对参考图像做均衡化的逆运算。

京东快递能发上海吗 京东发货快吗在上海

京东寄快递跨省需要多久 1.0天(平均值) 京东寄快递高效的5小时逆向上门取件服务;对商家开放快递系统平台,方便商家订单和账目核对;2000坐席的客户呼叫中心随时为商家提供咨询服务。跨省需···

我会看图写句子一年级下册 我会看图写故事一

源源给大家谈谈我会看图写句子一年级下册,以及我会看图写故事一年级下册应用的知识点,希望对你所遇到的问题有所帮助。 我会看图写句子一年级下册 我会看图写故事一年级下册 我会看图写···

10种代表秋天的景物 10种代表秋天的景物作文

秋天有什么景物描写 秋天有什么景物描写 10种代表秋天的景物 10种代表秋天的景物作文 10种代表秋天的景物 10种代表秋天的景物作文 秋天有什么景物描写1 枫叶的叶子红得像映山红,那么美,好像···