I found the mistake at line 132 of the code you have attached. If you notice, grayImage is already a binary image so thresholding it this way, will lead to binaryImage being a logical array with only zeros, hence the error.
binaryImage = grayImage > 100;
I believe you can just take:
binaryImage = grayImage ;
and then run the code to get the largest extracted blob. I hope this helps!