MATLAB: How to remove objects close to image border

classificationimage analysisimage processingimage segmentation

hello everyone, i have a problem related with image processing. btw, i have an image like this :
but i want to remove the object closest to the image border ( in this case, the closest one is on the right of the border)
do you know how to do that? thx before.

Best Answer

Sorry - I was sleeping, hence the delay on my part.
Simply crop the image with imcrop(), then call imclearborder(), then pad with padarray():
margin = 50; % Whatever
croppedImage = imcrop(binaryImage, [margin, margin, columns - 2 * margin, rows - 2 * margin]);
binaryImage = imclearborder(croppedImage);
binaryImage = logical(padarray(binaryImage, margin));