Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Animation of Mean Shift segmentation using MATLAB (with complete code)

Code (Note : The code is going to take some time(5-10 mins) to complete the execution as for different values of bandwidth Clustering has to be done separately)

clc

clear all

close all

warning off

preprocessing={};

rgbImage=imread('peppers.png');

redChannel=rgbImage(:, :, 1);

greenChannel=rgbImage(:, :, 2);

blueChannel=rgbImage(:, :, 3);

data=double([redChannel(:), greenChannel(:), blueChannel(:)]);

temp=100;

for i=10:100

    [n,m,not_required] = MeanShiftCluster(data',i,0);

    n=n';

    m=reshape(m',size(rgbImage,1),size(rgbImage,2));

    n=n/255;

    clusteredImage=label2rgb(m,n);

    preprocessing{temp}=clusteredImage;

    temp=temp-1;

end

for i=1:length(preprocessing)

    subplot(1,2,1);

    imshow(rgbImage);

    title('Orignial Image');

    ax=gca;

    ax.TitleFontSizeMultiplier=2;

    subplot(1,2,2);

    imshow(preprocessing{i});

    title('Segmented Image(Bandwidth Decreasing)');

    ax=gca;

    ax.TitleFontSizeMultiplier=2;

    pause(0.3);

end

 



Join us on Telegram: https://t.me/matlabcastor

No comments

Popular Posts