双上的 dohist - matlab
如何将表示为双精度的图像转换为可用于生成直方图的图像?
(与多希斯特:)
% computes the histogram of a given image into num bins.
% values less than 0 go into bin 1, values bigger than 255
% go into bin 255
% if show=0, then do not show. Otherwise show in figure(show)
function thehist = dohist(theimage,show)
% set up bin edges for histogram
edges = zeros(256,1);
for i = 1 : 256;
edges(i) = i-1;
end
[R,C] = size(theimage);
imagevec = reshape(theimage,1,R*C); % turn image into long array
thehist = histc(imagevec,edges)'; % do histogram
if show > 0
figure(show)
clf
pause(0.1)
plot(thehist)
axis([0, 256, 0, 1.1*max(thehist)])
end
how do i convert an image represented as double into an image that i can use to produce a histogram?
(with dohist:)
% computes the histogram of a given image into num bins.
% values less than 0 go into bin 1, values bigger than 255
% go into bin 255
% if show=0, then do not show. Otherwise show in figure(show)
function thehist = dohist(theimage,show)
% set up bin edges for histogram
edges = zeros(256,1);
for i = 1 : 256;
edges(i) = i-1;
end
[R,C] = size(theimage);
imagevec = reshape(theimage,1,R*C); % turn image into long array
thehist = histc(imagevec,edges)'; % do histogram
if show > 0
figure(show)
clf
pause(0.1)
plot(thehist)
axis([0, 256, 0, 1.1*max(thehist)])
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你只需要先标准化你的图像,为此你可以使用:
I am guessing that you just need to normalize your image first, to do this you can use:
您的代码看起来不错,您可以确保边界得到正确处理:
但这不是必需的,通常当您使用
imread 读取图像时,您会得到范围 [0,1] 或 uint8 [0,255] 的双图像()
。在这种情况下,如果需要,只需重新缩放到 [0,255] 即可。其他一些提示:
您可以像这样制作边缘向量:
在这种情况下,
theimage(:)
与reshape(theimage,1,R*C)
相同因为你想要一个长向量。Your code seems fine, you could make sure the bounds get treated correctly with:
But this shouldnt be necessary, usually you either get a double image ranging [0,1] or uint8 [0,255] when you read an image with
imread()
. Just rescale to [0,255] in this case if needed.Some other tips:
You can make the edges-vector like this:
And
theimage(:)
is the same asreshape(theimage,1,R*C)
in this case since you want one long vector.内置函数
hist
可以直接应用于double
类的图像。Matlab 文档链接
如果您怀疑图像有 N 位区间 [A,B] 上的分辨率,您可以直接在图像上调用
hist
(无需转换),例如:检索直方图和 bin 或
简单地绘制直方图。
The built-in function
hist
can be applied directly to images of classdouble
.Matlab documentation link
If you have an image which you suspect to have N bits of resolution on the interval [A,B], you can call
hist
directly on the image (without conversion) like:to retrieve the histogram and bins or
to simply plot the histogram.