From: Mike on 28 Jan 2010 18:54 Hi I am a newbie for image processing in matlab. I have a satellite image, including four bands (Band-sequential). I'd like to show it. First I use multibandread. Example is below: filename={'band1','band2','band3','band4'}; rows=1202; cols=1202; bands=1; size=[rows cols bands]; precision='uint8'; offset=0; interleave='bsq'; byteorder='ieee-le'; X=zeros([rows,cols,bands]); for ib=1:4 X(:,:,ib) = multibandread(filename{ib}, size, precision, offset, interleave, byteorder); end Then I use 'whos' Name Size Bytes Class Attributes X 1202x1202x4 46233728 double bands 1x1 8 double I'd like to show X, but don't know how. Any suggestion? Mike
From: Mike on 28 Jan 2010 19:37 On Jan 29, 7:54 am, Mike <sulfate...(a)gmail.com> wrote: > Hi > > I am a newbie for image processing in matlab. > I have a satellite image, including four bands (Band-sequential). > I'd like to show it. > First I use multibandread. Example is below: > > filename={'band1','band2','band3','band4'}; > rows=1202; cols=1202; bands=1; > size=[rows cols bands]; > precision='uint8'; > offset=0; > interleave='bsq'; > byteorder='ieee-le'; > X=zeros([rows,cols,bands]); > for ib=1:4 > X(:,:,ib) = multibandread(filename{ib}, size, precision, offset, > interleave, byteorder); > end > > Then I use 'whos' > > Name Size Bytes Class Attributes > > X 1202x1202x4 46233728 > double > bands 1x1 8 > double > > I'd like to show X, but don't know how. > Any suggestion? > > Mike Okay. I import only three bands. filename={'band1','band2','band3'}; rows=1202; cols=1202; bands=1; size=[rows cols bands]; precision='uint8'; offset=0; interleave='bsq'; byteorder='ieee-le'; X=zeros([rows,cols,bands]); for ib=1:3 X(:,:,ib) = multibandread(filename{ib}, size, precision, offset, interleave, byteorder); end Name Size Bytes Class Attributes X 1202x1202x3 34675296 double I use imtool: import from workspace. Then I found pixel values are all 1 for RGB. Why? Y=X(1:5,1:5,:); Y1=Y(:,:,1); >> Y1 Y1 = 106 104 101 102 107 118 117 111 102 118 125 117 106 105 122 123 113 102 103 119 117 107 102 99 109 Then I try for only greyscale image. Y1 5x5 200 double Then I found pixel values are as I expected. So how to import the RGB image? I read the help of 'imread'. There is no legal file formats as mine. Besides, why is Y1 total 200 bytes? Aren't the size supposed to 5*5*2 (bytes)? Mike
From: ImageAnalyst on 28 Jan 2010 21:54 Mike: Y1 is 200 bytes because it's a 5 x 5 x 8 bytes array and 5x5x8 = 200. Single is 4 bytes, and double is 8 bytes. uint8 is one byte. I'm not sure why you say that X is all 1's for red, green, or blue. I don't know why you say this since when you extract out the upper left 5 by 5 portion of the first ("red") channel it clearly has values in the range 99-125 - that's not 1, so I'm confused. When you say X=zeros([rows,cols,bands]); you're initializing it as a double. If your bands are uint8 you might try this X=uint8(zeros([rows, cols, 3])); There is a little known quirk in assigning uint8 arrays into a plane of a multidimensional array. If multibandread returns an 2D integer array then if you assign it to a 2D array X, it will recast it to an integer no matter if X was initialized as a uint8, or double, as long as X is 2D. BUT, and this is a big "but" and very unexpected, if you're stuffing the 2D integer array returned from multibandread into one plane of X and X is a multidimensional array, then it will make X a double. It won't make it an integer like it did when you initialized X as a 2D array. I know because I spent an hour tracking down this unexpected behavior earlier today. Now go back and re-read this paragraph very slowly, because it's detailed and not intuitive. If you initialize X as a 3D uint8 array then you will get a 3D uint8 array even after you're all done stuffing 2D uint8 arrays into the various color planes. I know it's quirky but that's the way it is. As you figured out in your second post, it's best if you just extract 3 of the color channels to display since our displays are RGB. In fact I don't even know if it's possible to display 4 or more channels - I'd really doubt it, unless you had a special monitor with more than 4 phosphors and a special video adapter. Regards, ImageAnalyst
From: Mike on 28 Jan 2010 23:19 On Jan 29, 10:54 am, ImageAnalyst <imageanal...(a)mailinator.com> wrote: > Mike: > Y1 is 200 bytes because it's a 5 x 5 x 8 bytes array and 5x5x8 = 200. > Single is 4 bytes, and double is 8 bytes. uint8 is one byte. > > I'm not sure why you say that X is all 1's for red, green, or blue. I > don't know why you say this since when you extract out the upper left > 5 by 5 portion of the first ("red") channel it clearly has values in > the range 99-125 - that's not 1, so I'm confused. Now I use X=zeros([rows,cols,bands],'uint8'); Then I can have the correct digital counts. > > When you say X=zeros([rows,cols,bands]); you're initializing it as a > double. If your bands are uint8 you might try this > X=uint8(zeros([rows, cols, 3])); Thank you. The same as above mentioned, except the '3'. I have already tried to use '3'. but stuck in X=zeros([rows,cols,3],'uint8'); %must use 'uint8', if double then the range is [0,1] %for ib=1:4 X(:,:,ib) = multibandread(filename{ib}, size, precision, offset, interleave, byteorder); ^ ^ for every ib %end > > There is a little known quirk in assigning uint8 arrays into a plane > of a multidimensional array. If multibandread returns an 2D integer > array then if you assign it to a 2D array X, it will recast it to an > integer no matter if X was initialized as a uint8, or double, as long > as X is 2D. as mentioned above. Now I use X=zeros([rows,cols,3],'uint8'); %must use 'uint8', if double then the range is [0,1] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ then all digital counts go to 1. BUT, and this is a big "but" and very unexpected, if > you're stuffing the 2D integer array returned from multibandread into > one plane of X and X is a multidimensional array, then it will make X > a double. It won't make it an integer like it did when you > initialized X as a 2D array. I know because I spent an hour tracking > down this unexpected behavior earlier today. Now go back and re-read > this paragraph very slowly, because it's detailed and not intuitive. > > If you initialize X as a 3D uint8 array then you will get a 3D uint8 > array even after you're all done stuffing 2D uint8 arrays into the > various color planes. > > I know it's quirky but that's the way it is. > > As you figured out in your second post, it's best if you just extract > 3 of the color channels to display since our displays are RGB. In > fact I don't even know if it's possible to display 4 or more channels > - I'd really doubt it, unless you had a special monitor with more than > 4 phosphors and a special video adapter. > Regards, > ImageAnalyst Thank you very much for the reply. But now I have another question. Follow the above post: Then I, as you say, I need only three colors: Y=X(:,:,[3 2 1]); Now I have an Y Y 1202x1202x3 4334412 uint8 I use imtool -> import from workspace. I can view it, do pixel value monitoring for RGB. Their values are all as I expect. Now I'd like to do the real works. Before this, I need to save Y. I use help to find available image formats. These formats, in fact, are not familiar to me. Also I use save as in imtool, it comes out so many formats. Question is: which is the format I can keep these digital counts unchanged? or the best one? To be more clear, in remote sensing, few people do compression. If I do image classification, I do it from raw digital counts. Unless there are so many bands of data like tens of them, or even hundreds. Besides, can I do it for four bands in matlab? It seems there are so many lossless compression: bmp, tiff (right???, correct me if it's wrong). Are their digital counts the same as the original Y? Thank you very much. Mike
From: ImageAnalyst on 29 Jan 2010 08:15
Mike: I'm not sure why all the digital values = 1 if you accept the output of multibandread() into a uint8 array. Sounds weird to me. You can save images in PNG format, which is an increasingly popular lossless compression format. -ImageAnalyst |