如何用Matlab实现直方图规定化
1个回答
展开全部
程序在这边,就不贴实验图片了
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)/(m*n); %求各灰度级的频率
% for j=1:i
% t(i)=t(i)+s(j); %求累计频率的和
%end
end
% 原始直方图的累积直方图
histc = cumsum(s);
% 规定直方图的累积直方图
J=imread('1.jpg'); h=rgb2gray(J); g=imhist(h);
matchhist=g/(m*n);
matchhistc = cumsum(matchhist);
N = length(matchhist);
M = double(intmax(class(f))) + 1;
% 映射的实现
tk = zeros(1,M); % 映射关系hist-->tk
%if strcmp(mapl,'SML') 以下为单映射规则(‘SML’)
tk(1) = 1;
linit = 2;
kinit = 0;
for k = 1:M %删除histc(k)=0的单元
if histc(k) == 0
kinit = kinit + 1;
else
break;
end
end
% 标记为SML为零的位置
indis0 = zeros(1,N);
for k = kinit:M
mappingL = zeros(size(matchhist));
% 为节省运算量而修改
for l = linit:N % 规定直方图从上一次最小处计算,节省运算时间
if matchhistc(l) == matchhistc(l - 1); %去掉相等为0的单元
continue;
end
mappingL(l) = abs(histc(k) - matchhistc(l));
if mappingL(l) == 0
indis0(linit) = 1;
end
end
mappingL(N) = abs(histc(k) - matchhistc(N));
indtemp1 = find(mappingL == 0);
indtemp2 = find(indis0 == 1);
mappingL(setdiff(indtemp1,indtemp2)) = inf;
[minmap,tk(k)] = min(mappingL(linit:N));
linit = tk(k) + linit - 1;
tk(k) = linit;
for k = 1:kinit - 1
tk(k) = tk(kinit);
end
end
%规定计算有意义
if N < M
for k = N:M
tk(k) = N;
end
end
histm = zeros(1,N);
for k = 1:M
histm(tk(k)) = histm(tk(k)) + H(k);
end
tk = tk - 1; % 方便灰度值的计算
% 图像的规定化
imagematch = zeros(size(f));
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)
imshow(f)
title('原始图像')
subplot(322)
imshow(imagematch)
title('直方图规定化后图像')
subplot(323)
bar(H,'g');
xlabel('灰度值')
ylabel('统计个数');
title('原始直方图')
subplot(324)
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('图像的规定化直方图');
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)/(m*n); %求各灰度级的频率
% for j=1:i
% t(i)=t(i)+s(j); %求累计频率的和
%end
end
% 原始直方图的累积直方图
histc = cumsum(s);
% 规定直方图的累积直方图
J=imread('1.jpg'); h=rgb2gray(J); g=imhist(h);
matchhist=g/(m*n);
matchhistc = cumsum(matchhist);
N = length(matchhist);
M = double(intmax(class(f))) + 1;
% 映射的实现
tk = zeros(1,M); % 映射关系hist-->tk
%if strcmp(mapl,'SML') 以下为单映射规则(‘SML’)
tk(1) = 1;
linit = 2;
kinit = 0;
for k = 1:M %删除histc(k)=0的单元
if histc(k) == 0
kinit = kinit + 1;
else
break;
end
end
% 标记为SML为零的位置
indis0 = zeros(1,N);
for k = kinit:M
mappingL = zeros(size(matchhist));
% 为节省运算量而修改
for l = linit:N % 规定直方图从上一次最小处计算,节省运算时间
if matchhistc(l) == matchhistc(l - 1); %去掉相等为0的单元
continue;
end
mappingL(l) = abs(histc(k) - matchhistc(l));
if mappingL(l) == 0
indis0(linit) = 1;
end
end
mappingL(N) = abs(histc(k) - matchhistc(N));
indtemp1 = find(mappingL == 0);
indtemp2 = find(indis0 == 1);
mappingL(setdiff(indtemp1,indtemp2)) = inf;
[minmap,tk(k)] = min(mappingL(linit:N));
linit = tk(k) + linit - 1;
tk(k) = linit;
for k = 1:kinit - 1
tk(k) = tk(kinit);
end
end
%规定计算有意义
if N < M
for k = N:M
tk(k) = N;
end
end
histm = zeros(1,N);
for k = 1:M
histm(tk(k)) = histm(tk(k)) + H(k);
end
tk = tk - 1; % 方便灰度值的计算
% 图像的规定化
imagematch = zeros(size(f));
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)
imshow(f)
title('原始图像')
subplot(322)
imshow(imagematch)
title('直方图规定化后图像')
subplot(323)
bar(H,'g');
xlabel('灰度值')
ylabel('统计个数');
title('原始直方图')
subplot(324)
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('图像的规定化直方图');
Sievers分析仪
2024-10-13 广告
2024-10-13 广告
是的。传统上,对于符合要求的内毒素检测,最终用户必须从标准内毒素库存瓶中构建至少一式两份三点标准曲线;必须有重复的阴性控制;每个样品和PPC必须一式两份。有了Sievers Eclipse内毒素检测仪,这些步骤可以通过使用预嵌入的内毒素标准...
点击进入详情页
本回答由Sievers分析仪提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询