How can I detect and crop the rectangular frame in the image?

Correct.

Yes.

Sure, if there is an object that has distinct hue or value (brightness). For hue probably wraparound / range thresholds would be needed, and maybe some other color space (rgb2lab?) would be better for that.

Possible sure, but probably typically less useful / more difficult to define useful criteria than in more intuitive / physical spaces like brightness.

These are distances in pixels between 1 and however large your image is. If you know how large the pixels are you could calculate the distance in pixels from a user specified distance in meters. Or use a percentage of image size. However the “1” is more to deal with pixel noise and not really related to the image size / resolution.

1 Like

Thanks a lot for the detailed answers.

Thank you. I tried to use this command in the code in different forms and lines; however, there was an error:

                       mask = skimage.morphology.isotropic_opening(filled, ent3w1.get())
                       mask_temp = mask
                       mask = skimage.segmentation.clear_border(mask)
                       if mask.count_nonzero() < mask_temp.count_nonzero():
                           mask = mask_temp
                       masked_result = image_rgb.copy()
                       masked_result[~mask, :] = 0

Error:
Exception in Tkinter callback
Traceback (most recent call last):
File “C:\Users.…\Python310\lib\tkinter_init_.py”, line 1921, in call
return self.func(*args)
File “C:\Users.…\temp.py”, line 146, in entw1
if mask.count_nonzero() < mask_temp.count_nonzero():
AttributeError: ‘numpy.ndarray’ object has no attribute ‘count_nonzero’


Also, without using such approaches, the output of the images which have intersected the image border is empty (or a completely black image). For instance, please see the below image in which the white ribbon tied to the quadrat has reached the image edge:

My mistake; it should be numpy.count_nonzero(mask) instead of mask.count_nonzero() etc.

1 Like

Do you think that I (as a beginner) may use the advanced approach i.e. “machine learning convolutional networks”? For instance, how can I prepare the training sets? Should these sets include some raw images on one hand, and the cropped areas on the other hand? what about the size of training sets? Is it a good idea to use AI for writing such code and model?
Thanks.

Maybe try a pre-trained model first, like:

1 Like

Now, I am glad to share the link of Easy Quadrat, which includes the techniques discussed here. Please find it at:

Thank you very much.

2 Likes