What is a joint histogram and a marginal histogram in image processing?

时间秒杀一切 提交于 2020-06-29 06:24:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/55874812/what-is-a-joint-histogram-and-a-marginal-histogram-in-image-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!