I have pushed this now.

Actually, nevermind my comment. isnan returns true for NA. Although I guess you could just skip a lot of the checks if isinteger returns true.

Thanks for the reviews (comment #11 & comment #12).
I will prepare a revised version

Other than Hartmut comments, looks fine to me. Small nitpick. Instead of checking for Inf, NaN, and < 0 (and forgetting NA), you can just do:
Also, are we just checking for sparse because Matlab does not support it? I think we lose nothing by letting it pass. What do we care if an histogram is internally stored as a sparse array?

I have had a look at the new file version (V3):
 my issues from comment #8 seem to be fixed (there doesn't seem to be any trouble with imcast...)
 Are all those tests Matlab compatible? (I have not checked this.)
 The following (Matlab compatible) input classes are currently not tested: int64, uint32, uint64. Do they work? (then let's test them) Or dont' they work for a good reason?(then let's document this in the help string). My short testing showed that they seem to work well, if that's true then please just add a test for each possible input class.

Attached otsuthresh_V3.m
please review
(file #45540)

Thanks for the review.
I will fix these comments, and send another patch for review.

I have had another closer look at this patch (file #40868). Here are my comments:
 There is a wrong character in the first lines, the last character in the first name of Carne.
 You could add a check to reject sparse inputs, Matlab claims to reject them.
 Several tests do not do what they pretend to do! For example this code "H = zeros(1,2,'int32'); H = [100 200];" does NOT give a vector of class uint32, but a vector of class double! So most of the integer input classes are untested.
 I have tried all integer input classes that Matlab claims to support. The following do NOT work: int8, int32, int64, uint32, uint64. Most of them don't work because "imcast" cannot deal with them.
@Avinoam: Could you fix this?
To get full coverage of all Matlab compatible input classes we would probably need to change imcast as well. Or can we live with an otsuthresh, that can only deal with the most common integer classes (the following already work: uint8, uint16, int16).

Please review

Matlab otsuthresh can get a column or a raw vector, but not
a matrix.
Attached a better version, with more tests.
All the tests will pass, after fixing two bugs in graythresh, see bug #45333.
There is still a "divide by zero" warning. It can be fixed
also in graythresh.
(file #40868)

Could you also confirm whether Matlab requires a column or array vector? And what happens if you pass a matrix? Would be nice to pass a matrix, one histogram per column, and get back an array of threshold values. This would allow to threshold an array of images in one go.

Thanks for reviewing.
I will add more test, as you suggested.

I have made some changes to it:
https://bitbucket.org/carandraug/octaveimage/commits/1664caa6b2729a50adb47700cbbdf9bb8194f522
When it comes to tests, since the point of this function is to use on processed histograms and to control the number of bins, can you use histograms that are not already used in the graythresh? Things like histograms with 10 bins, all bins with a value of zero, an histogram of length 0 and one, an histogram with values of class integer, an histogram with an Inf, etc?
At the moment, Octave comes with penny.mat which could be used for testing purposes and is very unlikely to change.

Thanks for reviewing, Hartmut.
A few answers:
 I will check Matlab results on the test images
 I have copied the demo from your demo in wiener2 ....
 Indeed we need more images in Octave for tests and demos. I raise this issue in the maintainers list and quoted you.

Thanks for your contribution!
I've had a look at this new function:
 This is a wrapper around the already existing functionality of Otsu's threshhold in Octave's graythresh function. So any wrong output values wouldn't be due to this new otsuthresh function anyways. But it would still be nice to have the outputs Matlab compatible. I have not checked the results of the included tests in Matlab, have you? Do they give the same results in Matlab?
 The included tests all pass.
(general remark: It would help to have some simple image files distributed along with the image package. Those could be used for tests and demos more easily. Or are there already some of those, in addition to phantom.m, that I just don't know of?)
I would like to see this new function added to the image package. (To keep up with Matlab changes, this was only introduced in R2016a...)

Implementing otsuthresh using graythresh.
Please review.
