MATLAB: Getting all points which are inside of the convexhull

convexhullImage Processing Toolbox

I have an image in 3D. I'd like to get all points which are inside its convexhull, but don't belong to the image. So I'd like to do something like this:
[K, V] = convhull(image);
result= zeros(size(image));
result(K == 1 & granule == 0) = 2;
It doesn't work, because K is of size x (the number of rectangles which create the convex hull) by 3.
How can I do it properly?

Best Answer

Don't use image as the name of your variable because it's the name of a built-in function.
Don't use convhull(). Use bwconvhull() instead. Then do an XOR with the binary image.