In the second case the code is:
image = imread(img);
...
I = imread(image);
This means, that image is the imported image already and using it as input for another imread call must fail with the shown error message.
You can find such problems easily using the debugger. See Doc: Debugger. Set a breakpoint in the failing line. Alternatively let Matlab stop automatically when the error occurs. Type this in the command window:
Then let the code run again. When it stops, check the values of the variables:
You will see, that it is not an appropriate input for imread, exactly as the error message tells already.
Best Answer