samedi 28 juin 2025

Statistics on image

With Red or Rebol R3, the vector! type is ideal for fast numerical calculations. 

Recently, Oldes has introduced new properties for vectors in R3 that allow you to obtain the descriptive statistics of a vector in one basic step. Great work!

An example

#!/usr/local/bin/r3
REBOL [ 
]
vect: #(float64! [1.62 1.72 1.64 1.7 1.78 1.64 1.65 1.64 1.66 1.74])
print query vect object!

The result:

signed: #(true)

type: decimal!

size: 64

length: 10

minimum: 1.62

maximum: 1.78

range: 0.16

sum: 16.79

mean: 1.679

median: 1.655

variance: 0.02529

population-deviation: 0.0502891638427206

sample-deviation: 0.0530094331227943


But this can also be applied to images!
An example 

#!/usr/local/bin/r3
REBOL [ 
]
cv: import 'opencv
with cv [
filename: %../images/lena.png         ; --use your own image
mat: imread/with filename 2 ;--read as grayscale image with one channel
imshow/name mat filename ;--display the image  with file name as title
moveWindow filename 200x10 ;--move window
vect: get-property mat MAT_VECTOR ;--get matrix values as a vector    
print query vect object!
print "A key to quit"
waitKey 0
]

The result:

signed: #(false)

type: integer!

size: 8

length: 65536

minimum: 2

maximum: 225

range: 223

sum: 4377641

mean: 66.7975006103516

median: 64.0

variance: 126148517.630557

population-deviation: 43.87338169177

sample-deviation: 43.873716422939


Efficient :)



 

Aucun commentaire:

Enregistrer un commentaire