% finds the nan boundingbox of an image, and crops to this box
%
% Y=cropnan(X); % trims off the pork at the edges
%
% [Y,Mlo,Nlo,Mhi,Nhi]=cropnan(X);

function [Y,M1,N1,M2,N2]=likeboundingboxinpostscript(X);

mask=chnan(0*X+1,0); % 1 where image exists, 0 where image doesn't exist

n=sum(mask);
m=sum(mask.');

[q w]=find(n~=0);
N1=min(w);
N2=max(w);
[q w]=find(m~=0);
M1=min(w);
M2=max(w);

Y=X(M1:M2,N1:N2);

