% Sample script for color image segmentation. % Octave notes: % We need the statistics package for kmeans % and we need the image package for the color conversion rgb2lab % % If these are not installed, run the following at Octave command line % for the image package. (or replace image with statistics if you don't % have the statistics package installed). % % pkg install -forge image % % Uncomment these lines for the first run through Octave %pkg load statistics %pkg load image clear; clc; [X,map]=imread('P355F1.jpg'); figure(1) image(X); colormap(map) Y=rgb2lab(X); nrows=size(Y,1); ncols=size(Y,2); % Strip off "L" channel, just use "a" and "b" channels Y1=Y(:,:,2:3); Y2=reshape(Y1,nrows*ncols,2); [idx,C,disterr]=kmeans(Y2,3); Z=reshape(idx,nrows,ncols); figure(2) imagesc(Z)