Discretized an image to compute mean gray per elements

Hello,
I wondering if it possibles to discretize an image (8bits) in regular square elements to compute a mean gray value per element ?

Hi @djacob,
I’ve done something similar to what you ask in the post with a python script.
This is a snippet of the main part, where you grid your image in square/rectangular:

n_col = 10;
n_row= 10;
tit_img=imp.getTitle()
h_img=imp.getHeight()      
w_img=imp.getWidth()
span_w=w_img/n_col
span_w=math.floor(span_w)
span_h=h_img/n_row
span_h=math.floor(span_h)
#subdivision
for r in range(1,n_col+1,1):
    for c in range(1,n_row+1,1):      
        curr_roi=Roi(span_w*(r-1),span_h*(c-1),span_w,span_h)
        curr_roi.setName(tit_img[0:len(tit_img)-4]+"_R"+str(c)+"_C"+str(r))        
        imp.setRoi(curr_roi)
        rm.addRoi(curr_roi)               

Of course you have to add some code before to get the image and the parameters, but I think that you can use it as a good starting point.

If you will have some problem to implement it, let me know I will try to help you!
have a nice day,
Emanuele Martini

2 Likes

Thank you very much !!
I’ll check out tomorrow but that looks pretty close of my request :slight_smile:

1 Like