Anyone can give some ligth of how can i do this in matlab? I really appreciate any hint.
Best regards, Gabriel Yuras
You have to convert each element of the INT32 matrix into binary format. This is easily done using the built-in matlab
funcion dec2bin, but first you should check either if the integer is negative or positive. Below is an example:
suppose 'l2_flags' is the int32 matrix, then for the value in the row=i, column=j:
> if l2_flags(i,j) >= 0 % positive or zero pass directly to DEC2BIN, with a leading '0'
> bin = ('0' dec2bin(l2_flags(i,j),n-1));
> else % negative, pass the negative of the input to DEC2BIN, add leading '1'
> bin = ('1' dec2bin(-l2_flags(i,j),n-1));
the result, 'bin' has 32 bits, each one representing a flag.
hope it helps, Uriel.
I wrote in to matlab and seems to work fine with bin = ['0' dec2bin(l2_flags(i,j),n-1)]; replacing the external parenthesis for square braquets and doing n=2.
My question is if this n=2 is it ok or should I use another number?.
I forgot to mention that N is the minimum number of bits used in the binary representation.
So it's okay to use N=2, nevertheless I would suggest to use N=32, bearing in mind that the non-significative zeros are also flags...
I make it the following way:
% read flags from a seawifs or modis HDF image
% convert them to unsigned integer
% with this method 32nd flag is lost, but it's fast
l2_flags = uint32(abs(double(hdfread('S2001232103832.L2_MLAC.x.hdf', 'l2_flags'))));
% make the land mask matrix of the same size as l2_flags. Zeros = land, ones - water
landMask = (bitand(l2_flags, 2) > 0);
bitand makes bitwise comparison of each element in l2flags with 2 (2 in decimal = 00000010 in binary, if only one byte is used) If second bit of an l2_flags element is not zero then bitand return 00000010, which is more than zero (and equal to 2 actually).
Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill