Assign value to image box

Hi,

Noob question here :smiley: : is there a way to assign a constant value for a rectangle in an image object?
I’m trying to have a black image and update it with white boxes. This would look something like:

while(True):
    img = sensor.snapshot().histeq() # data image
    imbin=img.clear() #mask image to be updated, initially set to zero
    for r in ROIS: #I establish a ROIS list
        blobs = img.find_blobs([thresholds[threshold_index]], roi=r[0:4], merge=False)
        if blobs: # Find index of blob with most pixels.
            most_pixels = 0
            largest_blob = 0
            for i in range(len(blobs)):
                if blobs[i].pixels() > most_pixels:
                    most_pixels = blobs[i].pixels()
                    largest_blob = i
	     #Now I want update binary image with value= (255,255,255) for blobs[largest_blob].rect()
	     imbin.set_value(blobs[largest_blob].rect(),(255,255,255)) #What is the best way for this??

Hi, I’m not sure what your code is doing:

imbin=img.clear()

Makes the image black then you try to use find_blobs() on it. This will have no affect.

Anyway, if you want to draw a rectangle use the draw_rect() method which can fill the rectangle.

Hello,

Thanks for reply.

imbin=img.clear()

Makes the image black then you try to use find_blobs() on it. This will have no affect.

Got your point. What would be then a good way to create a mask with zeros having same size as image?
So my purpose is to have 1 images “img” and a mask “imgbin”
Thanks and keep awesome support :smiley:
Marouen

Yeah, you need to allocate a second frame buffer. See the Frame differencing example scripts for how to do this.