Auto Cropping- Based on Labeling the Connected Components using MATLAB
Last Updated :
10 Jan, 2023
Auto Cropping Based on labeling the connected components is related to digital image processing. So, In this article, we will discuss the Auto Cropping-Based on labeling the connected components. Before that look at the basic terms which are required in this topic.
Auto Cropping
In terms of MATLAB, the auto-crop node is fix the position of inputs so that the content of the image is either focused at the center of the image without being resized. For auto-cropping, the image in MATLAB uses the below function.
imcrop()
- imcrop function- extracts a rectangular portion of an image. using this function you can specify the size and position of the crop region.
- Connected Components- Connected Components based on labeling, scan the object in an image as a set of adjacent pixels.
- Labeling- labeling means identifying and placing labels on each program of an object project in the image. in Binary image, it’s classified as 4-connected and 8-connected. for performing the labeling in MATLAB we use the Built-in function bwlabel() used to label the object in the binary image.
Syntax for Labeling
L = bwlabel(BW) % return the label matrix that contains labels
for the 8-connected object found.
L = bwlabel(BW, con) % return the label matrix where specify
the con connectivity.
[L,n] = bwlabel(__) %label function also return number of object
found in BW.
Suppose in an image all pixels are connected components that show similar intensity values.
Example 1:
Matlab
clc;
clear all;
close all;
warning off;
a= [1 1 1 0 0 0 0 0
1 1 1 0 1 1 0 0
1 1 1 0 1 1 0 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 1 1 0
1 1 1 0 0 0 0 0];
[x,y]= bwlabel(a,8);
|
Output:
Example 2:
Matlab
im = imread( 'GeeksforGeeks.png' );
imshow(im);
pause(1)
imcrop = imcrop(im,[20 30 40 80]);
imshow(imcrop);
|
imread() is used to reads the image from the file specified filename. Without the crop, the image shows the using imshow() function.
Output:
Now you can see the Auto crop image using the crop function with different intensity values.
If we changed the intensity value of the crop function then you will get a different figure as output.
imcrop = imcrop(im,[1090 200 3000 400]);
Share your thoughts in the comments
Please Login to comment...