From: Zhelyazko on
function pil(choose)
persistent im
switch choose
case 1
[im, res_im]=open_im
case 2

if isempty(im)
display('Image is empty');
return;
end
%blck should have some value otherwise it is going to crush
im_trans=block(im,blck)
end

So if you put the persistent im than it should work.
the only thing is that the blck should have some value
otherwise you are going to get ??? Undefined function or
variable 'blck'