You are on page 1of 3

OBJECTIVE:

To Study the Image Segmentation and Extraction with the help of a MATLAB code.

APPARATUS REQUIRED:
MATLAB 2018b software.

THEORY:
Image segmentation is the process of partitioning a digital image into multiple segments
(sets of pixels also known as super-pixels). The goal of segmentation is to simplify and/or
change the representation of an image into something that is more meaningful and easier to
analyze. Image segmentation is typically used to locate objects and boundaries (lines, curves,
etc.) in images. More precisely, image segmentation is the process of assigning a label to
every pixel in an image such that pixels with the same label share certain characteristics.

Segmentation partitions an image into distinct regions containing each pixels with similar
attributes. To be meaningful and useful for image analysis and interpretation, the regions
should strongly relate to depicted objects or features of interest. Meaningful segmentation is
the first step from low-level image processing transforming a greyscale or colour image into
one or more other images to high-level image description in terms of features, objects, and
scenes. The success of image analysis depends on reliability of segmentation, but an accurate
partitioning of an image is generally a very challenging problem.

In image processing, feature extraction starts from an initial set of measured data and builds
derived values (features) intended to be informative and non-redundant, facilitating the
subsequent learning and generalization steps, and in some cases leading to better human
interpretations. Feature extraction is a dimensionality reduction process, where an initial set
of raw variables is reduced to more manageable groups (features) for processing, while still
accurately and completely describing the original data set.
When the input data to an algorithm is too large to be processed and it is suspected to be
redundant (e.g. the same measurement in both feet and meters, or the repetitiveness of images
presented as pixels), then it can be transformed into a reduced set of features (also named
a feature vector). Determining a subset of the initial features is called feature selection. The
selected features are expected to contain the relevant information from the input data, so that
the desired task can be performed by using this reduced representation instead of the
complete initial data.
ALGORITHM:
1. Give the image file as the input to MATLAB for processing.
2. Colour image should be input.
3. Rgb2gray converts the colour image into black & white.
4. medfilt2 median filtering the image to remove noise from 2D image.
5. BW=edge(im1,’sober’) is used to find the edges of the colour image.
6. B=conv2(double(BW), doubleMSK)smoothing the image to reduce the number of
connected components.
7. libwlabelcalculating connected components.
8. M:max(max(L)) there will be m connected components. Here you can give a value
between 1 and m for L (connected components) in a loop you can extract all
connected components.
9. Also we can define the values of L like 1,2,3,4,………,17,18,…..so on, this value will
extract that particular data from the image.
10. At last we will display all the important images that we have segmented & extracted
from the image.

MATLAB CODE:

clc;
clear all;
k=input('Enter the file name','s');
im=imread(k);
im1=rgb2gray(im);
im1=medfilt2(im1,[3 3]);
BW = edge(im1,'sobel');
[imx,imy]=size(BW);
msk=[0 0 0 0 0;
0 1 1 1 0;
0 1 1 1 0;
0 1 1 1 0;
0 0 0 0 0;];
B=conv2(double(BW),double(msk));
B=conv2(double(BW),double(msk));
L = bwlabel(B,8);
mx=max(max(L))
[r,c] = find(L==18);
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end
figure,imshow(im);
figure,imshow(im1);
figure,imshow(B);
figure,imshow(n1,[]);
OUTPUTS:

You might also like