问题描述
什么是图像处理中的联合直方图和边际直方图,以及它们如何工作以及如何构建联合直方图和边际直方图。如果我有一个10维的特征空间,并且想建立一个直方图,每个维量化为20个值。如何计算联合直方图和边际直方图的总箱数?
我假设您知道一般的直方图。 N维特征空间中数据的联合直方图为N维。您只需将数据点放入N维单元(通常是N个1维网格的笛卡尔积)。边际直方图小于一维或多维被忽略的N维直方图。联合和边际直方图与
让我们计算联合直方图
h = histcounts2(x,y,-10:10,-10 :10);
让我们显示联合直方图和边际直方图,可以通过积分获得一维上的联合直方图,或者通过分别为数据轴创建一维直方图。这里的边际直方图仅通过计算1D直方图(忽略其他数据维)而创建。
子图(位置,[0.35,0.35,0.6,0.6]);
im = imagesc(-10:10,-10:10,h。’);
im.Parent.YDir =正常;
轴图像;
title(联合直方图(x,y));
子图(位置,[0.43,0.1,0.45,0.15]);
直方图(x,-10:10);
camroll(180);
标题(边际直方图x);
子图(位置,[0.2,0.4,0.15,0.55]);
直方图(y,-10:10);
camroll(90);
标题(边际直方图y);
可以很好地看到,边际直方图恰好对应于一个方向上的联合直方图的积。
What is a joint histogram and a marginal histogram in image processing and how do they work and how to construct one, with simple examples if possible.
For example, if I have a feature space of 10 dimensions and want to build a histogram with each dimension quantize into 20 values. How to calculate the total bins for the joint histogram and for the marginal histogram?
I assume you know what histograms are in general. Joint histograms of data in an N-dimensional feature space are N dimensional. You just put the data points into N-dimensional bins (typically Cartesian products of N 1-dimensional grids). Marginal histograms are less than N-dimensional histograms where one or more dimension has been ignored. Joint and marginal histograms are very similar to joint/marginal distributions.
How to compute them depends on your specific situation. You could compute marginal histograms from joint histograms by integrating over some dimensions or you could build them the same way as joint histograms but with fewer dimensions. In Matlab, histcounts2
for example computes a joint histogram of 2D data. For higher dimensional data, accumarray
might be of help. In Python with NumPy, histogramdd
generates multi-dimensional histograms. Typically the N-dimensional bins are Cartesian products of bins in each dimension and the resulting histograms are simple Numpy arrays (in Python) or matrices (in Matlab).
Simple example in N=2D (in Matlab)
Let's create some data first
x = 3*randn(1e4, 1);
y = randn(1e4, 1);
scatter(x, y, '.');
xlim([-10,10]);
ylim([-10,10]);
pbaspect([1,1,1]);
Let's compute the joint histogram
h = histcounts2(x, y, -10:10, -10:10);
Let's display the joint histogram and on each side the marginal histograms, which could have been obtained either by integrating the joint histogram over one dimension or by creating 1D histograms for the data axes separately. Here the marginal histograms are created by just computing 1D histograms (ignoring the other data dimension).
fig = figure;
subplot('Position', [0.35, 0.35, 0.6, 0.6]);
im = imagesc(-10:10, -10:10, h.');
im.Parent.YDir = 'normal';
axis image;
title('joint histogram (x,y)');
subplot('Position', [0.43, 0.1, 0.45, 0.15]);
histogram(x, -10:10);
camroll(180);
title('marginal histogram x');
subplot('Position', [0.2, 0.4, 0.15, 0.55]);
histogram(y, -10:10);
camroll(90);
title('marginal histogram y');
One can see nicely that the marginal histograms just correspond to add-ups of the joint histogram along a directions.
这篇关于什么是图像处理中的联合直方图和边际直方图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!