Compare watershed function of MATLAB and OpenCV (see this SO question).
Created
April 1, 2016 11:39
-
-
Save amroamroamro/6423064ee20ad1a3d4de93ad7d68d8f5 to your computer and use it in GitHub Desktop.
watershed: MATLAB vs. OpenCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 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