MATLAB: Erasing the boarders in an Image

cell arraysdeep learningimage processingmatrix

Hi
I would if it is possible in MATLAB to remove the black sides on the boarder of this image basically on right side and bottem side
Herein the code
close all;
clc;
%% Initalize the data
dataDir= fullfile('Data/');
exts = {'.jpg','.png','.tif','BMP'};
imds = imageDatastore(fullfile(dataDir),...
'IncludeSubfolders',true,'FileExtensions','.BMP','LabelSource','foldernames');
countEachLabel(imds);
[TrainData, TestData] = splitEachLabel(imds,0.5);
size(TrainData);
countEachLabel(TrainData);
numImages = numel(TrainData.Files);
for i = 1:numImages
img = readimage(TrainData, i);
img=rgb2gray(img);
img3= im2double(imresize(img, [100 100], 'bicubic'));
end

Best Answer

Do you want to
  1. crop it away, which will give a different size image?
  2. Or set it to white, which would leave the image the same size?
Also, what does "Enhacing" mean? No such word. Does it mean "enhancing" or "erasing"? If erasing, you need to answer my questions as to how you want to erase (get rid of) the black border. If enhancing, you need to define exactly what that means.
To crop you could use imcrop() but it's probably easiest to just use indexing:
img = img(row1 : row2, col1 : col2, :); % Works for either rgb or grayscale image.
I assume you can find the rows and columns and that it's known and fixed for all images. If it moves around and changes size (which is doubtful but possible), you'd need code to find them.