View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Fast mutual information, joint entropy, and joint histogram calculation for N-D images

5.0 | 1 rating Rate this file 18 Downloads (last 30 days) File Size: 1.76 KB File ID: #41714 Version: 1.9

Fast mutual information, joint entropy, and joint histogram calculation for N-D images


ja (view profile)


13 May 2013 (Updated )

Built for 'highest possible' speed. Can handle any number of dimensions, given sufficient memory.

| Watch this File

File Information

This uses no for-loops - only index manipulation. Intended use is for iterative programs where increased speed pays off, but works just fine for individually controlled use as well - though in this case the user may want to adjust the function to include various parameters as input variables (for iterative programs these are usually constant, so they are set to typical values within the function).

No error checking is used, as that could slow things down and is generally unnecessary for an iterative program presumably using fixed image sizes and pixel values.

Returns joint histogram, mutual information, and joint entropy. It is expected that no one will need all three, so instructions on how to remove that which is not needed is included.

Required Products Image Processing Toolbox
MATLAB release MATLAB 8.1 (R2013a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
15 Feb 2017 wentao xu

17 Aug 2015 ja

ja (view profile)

ND here means "n-dimensional". In other words, you can have a 2-d image, a 3-d image, 4-d image, et cetera...

It's a good idea to be able to use more than two images, though. I didn't even know there was a need for that. I'll update when I have time to figure out how to do it.

Comment only
16 Aug 2015 Aria

Aria (view profile)

This program is not for nD, as it just can get two images. When it is said nD I thought it can handle n images with the same spatial size, e.g. Multi- or hyper-spectral satellite images

Comment only
08 May 2014 ja

ja (view profile)

That error means that at least one value in at least one of your images is not a non-negative integer value.

I have not added error checking, as the point of this is speed. But if you wanted to ensure that you do not get this error, you can add the following lines to the top of this function:
J = J - min(J(:));
K = K - min(K(:));
J = round(255.4*J/(max(J(:)));
K = round(255.4*J/(max(J(:)));

All this does is recast the image into the 0-255 range. This should avoid the error you were getting, as long as you don't have any NaN or complex pixel values. Again, I didn't want to add this to the code, as I suspect the main use for this will be for iterative programs, and recasting is usually handled well in advance of any attempt to obtain MI or joint entropy..

But, if you add these lines and it continues not to work, please let me know, and if possible include the data you are using.

Comment only
08 May 2014 Nicolas Yu

Nicolas Yu (view profile)

have you tested your code?
There is a bug that when calculating h(x,y).

Bug information:
Subscript indices must either be real positive integers or logicals.

Error in ent (line 39)
jhist(yy) = xx;

Error in testENT (line 6)
[jhist, jent, MI] = ent(imgA,imgB);

Comment only
09 Sep 2013 1.3

Now returns joint histogram and joint entropy by default (can be changed easily by user).
Changed the 'find' function to logical indexing for increased speed.
Removed the dimensional dependencies, so it now works for any image dimensions.

11 Sep 2013 1.4

updated description
included 'example data' in the comments
added a variable for slightly higher indexing speed

13 Sep 2013 1.6

Now also returns mutual information.

19 Sep 2013 1.7

condensed the comments in the code to only what is necessary to modify the function..

25 Sep 2013 1.8

fixed a silly mistake that needlessly increased the MI calculation time by about 10%

16 Oct 2013 1.9

Found that using array multiplication instead of meshgrid indexing increased the MI calculation slightly.

Contact us