Skip to content

Instantly share code, notes, and snippets.

@amroamroamro
Created April 1, 2016 11:39
Show Gist options
  • Save amroamroamro/6423064ee20ad1a3d4de93ad7d68d8f5 to your computer and use it in GitHub Desktop.
Save amroamroamro/6423064ee20ad1a3d4de93ad7d68d8f5 to your computer and use it in GitHub Desktop.
watershed: MATLAB vs. OpenCV
%% data
load watershedExample.mat
A = rgbImage(:,:,1);
marker = int32(cv.dilate(uint8(marker)));
%% MATLAB
L = watershed(A);
m = (marker > 0) | (L == 0);
m = im2uint8(m);
m(:,:,3) = 0;
figure(1)
surf(A, 'FaceAlpha',0.5, 'EdgeAlpha',0.25), hold on
warp(imfuse(rgbImage,m,'blend'))
hold off, axis tight vis3d
title('MATLAB watershed')
colormap(flipud(hot(64))), colorbar
rotate3d on
%% OpenCV (using https://github.com/kyamagu/mexopencv)
L = cv.watershed(rgbImage, marker);
m = (marker > 0) | (L == -1);
m = im2uint8(m);
m(:,:,3) = 0;
figure(2)
surf(A, 'FaceAlpha',0.5, 'EdgeAlpha',0.25), hold on
warp(imfuse(rgbImage,m,'blend'))
hold off, axis tight vis3d
title('OpenCV watershed')
colormap(flipud(hot(64))), colorbar
rotate3d on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment