79 lines
2.4 KiB
JavaScript
Executable File
79 lines
2.4 KiB
JavaScript
Executable File
|
|
function histogram(data, range_min, range_max, bin){
|
|
|
|
/*
|
|
Creates histogram on data.
|
|
|
|
Args:
|
|
data (tuple, array, ArrayList or Array): input data can be multi-dimensional or nested.
|
|
range_min (int, optional): minimum histogram value. Default is floor(min(data))
|
|
range_max (int, optional): maximul histogram value. Default is ceil(max(data))
|
|
bin(int or float, optional): if int means number of bins. If float means bin size. Default = 1.0.
|
|
Returns:
|
|
tuple: (ydata, xdata)
|
|
|
|
*/
|
|
flat = flatten(data)
|
|
if (!is_defined(range_min)) range_max = null
|
|
if (!is_defined(range_max)) range_max = null
|
|
if (!is_defined(bin)) bin = 1.0
|
|
if (range_min == null) range_min = Math.floor(Math.min.apply(null,flat))
|
|
if (range_max == null) range_max = Math.ceil(Math.max.apply(null,flat))
|
|
|
|
print("Min "+ range_min)
|
|
print("Max "+ range_max)
|
|
if (is_float(bin)){
|
|
|
|
bin_size = bin
|
|
n_bin = Math.ceil((range_max - range_min)/bin_size)
|
|
print(bin_size)
|
|
print( n_bin)
|
|
}
|
|
else{
|
|
n_bin = bin
|
|
bin_size = (range_max - range_min)/bin
|
|
}
|
|
|
|
print("n_bin" + n_bin)//
|
|
print("bin_size" + bin_size)
|
|
|
|
result = []; size=n_bin; while(size--) result.push(0)
|
|
|
|
for (d in flat){
|
|
b = Math.floor( (flat[d] - range_min) / bin_size)
|
|
if ((b >=0) && (b < n_bin)){
|
|
result[b] = result[b] + 1
|
|
}
|
|
}
|
|
|
|
result_x = []; size=result.length; p=range_min; while(size--) {result_x.push(p); p+=bin_size }
|
|
|
|
return [result,result_x]
|
|
}
|
|
|
|
|
|
h = histogram(data=im1.read(), undefined, undefined, bin=0.1)
|
|
hd=h[0]; xd = h[1]
|
|
/*
|
|
image = Utils.grayscale(src1.getOutput())
|
|
data = Convert.toUnsigned(image.getData().getDataBuffer().getData())
|
|
h = histogram(data, range_min=0, range_max=255)
|
|
hi=h[0]; xi = h[1]
|
|
|
|
if (plots == null){
|
|
plots = plot((hd,hi), ("Data", "Image"), (xd, xi), title = "Histo")
|
|
} else{
|
|
plots[0].getSeries(0).setData(xd,hd)
|
|
plots[1].getSeries(0).setData(xi,hi)
|
|
}
|
|
if (plots[0].displayable == false){
|
|
abort()
|
|
}
|
|
|
|
ov_cross.update(new Point((ov_cross.position.x+1) % size.width ,(ov_cross.position.y+1) % size.height))
|
|
|
|
sleep(0.1)
|
|
*/
|
|
|
|
print (hd.length)
|
|
print (xd.length) |