Hi everybody,
I would like to write a macro in which I determine the 100 largest and smallest pixel values on a detector.
Only pixels in a certain region of interest should be considered.
I have already successfully implemented the criterion of whether a pixel is within the ROI.
I also have a solution in mind for determining the 100 largest and smallest values, which I think should already work.
When I run the macro, the array with the values also fills up at first, but at some point it stops and no new values are added.
Do you guys have an idea why this is not working? Could there be some kind of buffer overflow or so? Or do I have a fundamental error in my macro?
I added my macro and an exemplary result below
Thanks for any help or hint :)
Best,
Matteo
! Calculates the max and min intensity (from the 100 largest and lowest pixels) in a circle centered in the detector plane
! Calculates the uniformity = min/max from the in that circle
detector = 28
size = 51
max_radius = 25
center = 26
total = size*size
average = 100
minInt = 10000000
maxInt = -1
uniformity = 0
idx = 1
DECLARE pixel_array, DOUBLE, 1, total
DECLARE top100, DOUBLE, 1, average
DECLARE bottom100, DOUBLE, 1, average
! NSTR 1, 0, 0, 0, 0, 1, rays, 0, 0, 0, 0
FOR x, 1, total, 1
pixel_array(x) = NSDD(1, detector, x, 1)
temp = pixel_array(x)
NEXT
FOR i, 1, average, 1
top100(i) = 0
bottom100(i) = 10000
NEXT
PRINT "----"
FOR i, 1, size, 1
FOR j, 1, size, 1
temp_x = i - center
temp_y = j - center
normalized_radius = SQRT(POWR(temp_x,2) + POWR(temp_y,2)) / max_radius
IF (normalized_radius <= 1)
valueTop = pixel_array(idx)
valueBottom = pixel_array(idx)
FOR y, 1, average, 1
IF (valueTop > top100(y))
top100(y) = valueTop
valueTop = 0
ENDIF
IF (valueBottom < bottom100(y))
bottom100(y) = valueBottom
valueBottom = 100000
ENDIF
NEXT
ENDIF
idx = idx + 1
NEXT
NEXT
sum_top = 0
sum_bottom = 0
FOR y, 1, average, 1
sum_top = sum_top + top100(y)
sum_bottom = sum_bottom + bottom100(y)
NEXT
topMean = sum_top / average
bottomMean = sum_bottom / average
uniformityMean = bottomMean / topMean
PRINT "Mean Uniformity = ", uniformityMean
uniformity = minInt / maxInt
PRINT "-----------------"
PRINT "maxInt = ", topMean
PRINT "minInt = ", bottomMean
PRINT "Uniformity = ", uniformityMean
SETOPERAND 5, 8, topMean
SETOPERAND 7, 8, bottomMean
SETOPERAND 9, 8, uniformityMean
FOR z, 1, average, 1
temp_1 = top100(z)
FORMAT 4 INT
PRINT $STR(z),
FORMAT 6.4
PRINT " = ", temp_1
NEXT
