Erasing the boarders in an Image
Show older comments
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
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 12 Nov 2020
Simply crop out the black frame. Something like this:
Img_frameless = Img_in(y_min:y_max,x_min:x_max); % for a grayscale image
Img_framelessRGB = Img_rgb(y_min:y_max,x_min:x_max,:); % for an RGB-image
HTH
1 Comment
Bjorn Gustavsson
on 12 Nov 2020
if you want to set the border to white just do this:
Imax = max(Img_in(:)); % just to get the peak intensity, which might depend on data-type
Img_WB = Img_in;
Img_WB(1:top_row_lb,:,:) = Imax;
Img_WB(bot_row_ub:end,:,:) = Imax;
Img_WB(:,1:left_col_rb,:) = Imax;
Img_WB(:,right_col_lb:end,:,:) = Imax;
HTH
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!