Matlab
Program for Cropping Binary Image : Matlab Code
Objective of the Program:
Program takes a black and white image as input. It removes the black portion and gives the white portion of the image.
Input: Gray or binary image (for example consider the image below)
Output: Gray or binary image (as below)
MATLAB Code:
img = imread('path of image');
[row col] = size(img);
for i = 1:row
if sum(img(i,:)) > 0
top = i;
break
end
end
for i = row:(-1):1
if sum(img(i,:)) > 0
bottom = i;
break
end
end
for i = 1:col
if sum(img(:,i)) > 0
left = i;
break
end
end
for i = col:(-1):1
if sum(img(:,i)) > 0
right = i;
break
end
end
output = img(top:bottom, left:right);
imshow(output);
|
Popular Articles:
1. matlab-cropping-binary-image-algorithm
Objective of the Program:
Program takes a black and white image as input. It removes the black portion and gives the white portion of the image.