After clustering in image, I want to visualize the result. To do so, I first reshape an RGB image to 3*size.

The result of BSMC is the set of indices after clustering. So I change the value at the pixel. But the result is not what I wanted.

How to show correctly segmentation result?

X = imread('image3.jpg');
%X = imresize(X, 0.2);
[height width depth] = size(X);
X = reshape(X, [depth height*width]);
X = double(X);
ppp = BSMC(X);
ppp = ppp.partition;

ppp = BSMC(X, 'initial_partition', ppp);
ppp = ppp.partition;

for (i = 1:size(ppp, 2) )
    color = zeros(3, 1);
    color(1) = randi([0,255]);
    color(2) = randi([0,255]);
    color(3) = randi([0,255]);

    for (j = 1:size(ppp(i).indices, 2) )
        X(:, ppp(i).indices(j) ) = color;

X = reshape(X, [height width depth]);
X = uint8(X);

original image my result


1 Answer 1


some pointers for you to figure out the solution:

  1. you can convert segmentation results to CONTOURS and then plot contours, with thick boundary lines.

  2. first convert the image to grayscale,

    x = rgb2gray(x);
    img(:,:,1) = x; img(:,:,2) = x; img(:,:,3) = x;

    now, for each cluster you can modify the color for that part of image. say for example row1, col1, keep the index for class 1: for i=1:size(row1,1) img2(row1(i), col1(i), 1) = 200; end in the end show image with modified colors.

  3. show image, then hold on, then show ONLY one cluster at a time as a region filled with a solid color, then set transparency to 50%.

    two ways

    to set transparencey: 
    set(h, 'AlphaData', alpha_data); % e.g. alpha_data = 0.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.