I would like to add a rectangular patch to an image similar to the one shown in the below giff.
refer to the first image on the left
At the same time,I should be able to control the stride and the size of the rectangular patch.This would allow me to occlude different areas of the image.
I tried using the following script,but it didn’t really produce the results shown in the giff above.Any ideas on what changes can be made in the code to achieve the desired result
Summary :Using opencv python,I would like to add rectangular patches of different sizes at different locations in an image,thereby occluding that particular part of the image.
Code and result obtained after executing the code
def get_occluded_img(img,occ_size,occ_pixel,occ_stride): img_size=int(img.shape[-1]) output_height=int(math.ceil((img_size-occ_size)/occ_stride+1)) output_width=int(math.ceil((img_size-occ_size)/occ_stride+1)) for h in range(output_height): for w in range(output_width): h_start=h*occ_stride w_start=w*occ_stride h_end=min(img_size,h_start+occ_size) w_end=min(img_size,w_start+occ_size) occ_image=img.copy() occ_image[h_start:h_end,w_start:w_end,:]=occ_pixel return occ_image