0% found this document useful (0 votes)
31 views6 pages

DIP Assignment 6

This document contains code and output for two digital image processing segmentation techniques: k-means clustering based segmentation and region growing segmentation. For k-means clustering based segmentation, the code takes an image, number of clusters, and performs k-means clustering to segment the image into that number of regions. For region growing segmentation, the code takes an image, threshold value, seed points, performs seeded region growing segmentation of the image and outputs the segmented image and number of regions.

Uploaded by

Saad Ali Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views6 pages

DIP Assignment 6

This document contains code and output for two digital image processing segmentation techniques: k-means clustering based segmentation and region growing segmentation. For k-means clustering based segmentation, the code takes an image, number of clusters, and performs k-means clustering to segment the image into that number of regions. For region growing segmentation, the code takes an image, threshold value, seed points, performs seeded region growing segmentation of the image and outputs the segmented image and number of regions.

Uploaded by

Saad Ali Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Digital Image Processing

Assignment 6

Submitted by:
Student Name: Syed Saad Ali Shah

Enrolment No.: 01-134-171-075

Student Name: Abdul Hussain

Enrolment No.: 01-134-171-001

Student Name: Mubeen Ahmad

Enrolment No.: 01-134-171-090

Class and Section: BSCS-7A

Submitted to: Dr. Sumaira Kausar

Department of Computer Science


BAHRIA UNIVERSITY, ISLAMABAD
Clustering based Segmentation

Code:
img = getimage(handles.axes1);

s = str2double(get(handles.meank,'string'));

means3 = imsegkmeans(img, s);

axes(handles.axes1); imshow(img);

title('Original');

axes(handles.axes2); imshow(label2rgb(means3));

title([num2str(s),' - Mean'])

Output:
Region Growing Clustering

Code:
imgg = getimage(handles.axes1);

th = str2double(get(handles.threshold,'string'));

sp = str2double(get(handles.seedpoints,'string'));

img = rgb2gray(imgg);

smoothed = medfilt2(img);

seed = mode(smoothed(find(smoothed ~= mode(smoothed, 'all'))), 'all');

%[g, NR, SI, TI] = regiongrow(smoothed, double(seed)-5, 80);

[g, NR, SI, TI] = regiongrow(smoothed, double(seed)-sp, th);

pp = medfilt2(g);

axes(handles.axes2); imshow(smoothed);

%title("Smooth");

title(['Threshold: ',num2str(th),' Seed Points: ',num2str(sp)])

axes(handles.axes3); imshow(g);

title('Region Growing Segmented');

function [g, NR, SI, TI] = regiongrow(f, S, T)

f = double(f);

if numel(S) == 1

SI = f == S;

S1 = S;

else

SI = bwmorph(S, 'shrink', Inf);

J = find(SI);

S1 = f(J);

end

TI = false(size(f));
for K = 1:length(S1)

seedvalue = S1(K);

S = abs(f - seedvalue) <= T;

TI = TI | S;

end

[g, NR] = bwlabel(imreconstruct(SI, TI));

Output:

You might also like