From: Matteo on
I often write image manipulation code to apply to geophysical residual data or DEM, with all sorts of value ranges, including negative values.

Is there any built in function in Matlab that would test input data to verify if it is an image (say with values within standard intensity range), and if not it converts it using mat2gray.

If not, does anybody have any suggestion as to how it could be accomoplished? Thank you
From: Walter Roberson on
Matteo wrote:

> Is there any built in function in Matlab that would test input data to verify if it is an image (say with values within standard intensity range), and if not it converts it using mat2gray.

No, there is not.

> If not, does anybody have any suggestion as to how it could be accomoplished?

if (isfloat(I) && max(abs(I)) > 1)) || ndim(I) > 3 ||
~ismember(class(I),{'uint8','uint16', 'logical'})
I = mat2gray(I);
end


I would need to cross-check the reference material to see if I got the
list of permitted integer classes right... and I really don't think that
mat2gray is going to have any success in converting an array of 4 or
more dimensions to grayscale... or any success in converting non-numeric
data such as cell arrays or struct arrays or objects ... but we give you
what you asked for, not what you might have wanted ;-)
From: Matteo on
> I really don't think that
> mat2gray is going to have any success in converting an > array of 4 or more dimensions to grayscale... or any > success in converting non-numeric
> data such as cell arrays or struct arrays or objects ...

Hi, thank you so much for your reply. I am a bieginner user, but I understand the logic of your code and I think I can adjust it to fit it to my case.
The only thing I am not too sure is why the assumption of more than 4 dimensions. The data I work with is always a matrix of numerical values Z (with accompanying X and Y matrix, but those I keep separate during processing), with maybe unusual ranges. Thank you
From: Walter Roberson on
Matteo wrote:
>> I really don't think that
>> mat2gray is going to have any success in converting an > array of 4 or more dimensions to grayscale... or any > success in converting non-numeric
>> data such as cell arrays or struct arrays or objects ...

> Hi, thank you so much for your reply. I am a bieginner user, but I understand the logic of your code and I think I can adjust it to fit it to my case.
> The only thing I am not too sure is why the assumption of more than 4 dimensions. The data I work with is always a matrix of numerical values Z (with accompanying X and Y matrix, but those I keep separate during processing), with maybe unusual ranges. Thank you

Your question was about a function or logic to detect whether a given
matrix was not an image, and if it was not, to convert it using
mat2gray. You did not restrict what the matrix *might be*, but you did
require that if it was found *not* to be consistent with being an image,
that it had to be processed through mat2gray. Now, no matrix with
dimension 4 or larger can be an image, so under the rules of your
question, the function or logic *must* use mat2gray() on the matrix...
From: Matteo on
Hello again.
I see what you mwean, your logic is flawless. I realize my question was not specific enough. I think a lack of more indepth knowledge, and also mistakenly assumed familiarity with Geophysical residuals.

I think a better suited question for my case would be: Is there any way to automatically detect if the input matrix of raw data (which is in double format, by the way) does not have the range of values that would normally be expected for an intensity image (0 to 1)? And if so, convert it to that scale using mat2gray.
For instance, one of my matrices have data between negative 5.9834 and positive 2.9969. I hope this is more clear. :-) Thank you