From: Mike on 29 Jan 2010 20:20 On Jan 29, 9:15 pm, ImageAnalyst <imageanal...(a)mailinator.com> wrote: > 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. because 'zeros' by default output double: [0,1] and uint8: [0,255]. So [0,255] is scaled to [0,1]. > > You can save images in PNG format, which is an increasingly popular > lossless compression format. > -ImageAnalyst Thank you for suggestions. Mike
From: ImageAnalyst on 29 Jan 2010 21:20 I don't agree Mike. If you have a function that returns a uint8 in the range 0-255, and accept it into a variable that was previously declared as a 3D uint 8 array (even if you declared it as 3 planes but assigned 4 planes as you did), then the result will be a uint8 array in the range 0-255. If you do the same thing but the previously initialized variable was a 3D double array, then the result is converted into a double array with the range 0-255. There is no scaling of 0-255 into 0-1 in either case. Moreover, if X is a double array there is nothing that says it has to be in the range 0-1 like you say. It can take any value from -1.7977e+308 to +1.7977e+308. Here's proof: %-------------------------------------------------------------------------- function test clc; close all; clear all; workspace; % Display workspace panel. rows = 500; cols = 500; % Try it with X being declared as uint8 X = zeros([rows, cols, 3],'uint8'); %must use 'uint8', if double then the range is [0,1] whos X; sizeOf2DArray = [rows cols]; for ib=1:4 X(:,:,ib) = ReturnUint8Array(sizeOf2DArray); end whos X; max(max(X)) % Try it with X being declared as uint8 XX = zeros([rows, cols, 3],'double'); %must use 'uint8', if double then the range is [0,1] whos XX; for ib=1:4 XX(:,:,ib) = ReturnUint8Array(sizeOf2DArray); end whos XX; max(max(XX)) return; %-------------------------------------------------------------------------- function uint8Array = ReturnUint8Array(inputArray) realArray = 255 * rand(inputArray(1), inputArray(2)); uint8Array = uint8(realArray); return; %-------------------------------------------------------------------------- Even if you're using multibandread() (instead of the ReturnUint8Array in my simple little demo), the help for multibandread() says "a precision of 'uint8=>uint8' (or '*uint8') will return the data as a UINT8 array." meaning it can go from 0-255. So I still don't understand why you say "then all digital counts go to 1. " when you declared X as uint8. That should not happen. But whatever, as long as you got it working....
From: Mike on 30 Jan 2010 01:54 On Jan 30, 10:20 am, ImageAnalyst <imageanal...(a)mailinator.com> wrote: > I don't agree Mike. If you have a function that returns a uint8 in > the range 0-255, and accept it into a variable that was previously > declared as a 3D uint 8 array (even if you declared it as 3 planes but > assigned 4 planes as you did), then the result will be a uint8 array > in the range 0-255. If you do the same thing but the previously > initialized variable was a 3D double array, then the result is > converted into a double array with the range 0-255. There is no > scaling of 0-255 into 0-1 in either case. Moreover, if X is a double > array there is nothing that says it has to be in the range 0-1 like > you say. It can take any value from -1.7977e+308 to +1.7977e+308. > Here's proof: > %-------------------------------------------------------------------------- > function test > clc; > close all; > clear all; > workspace; % Display workspace panel. > > rows = 500; > cols = 500; > % Try it with X being declared as uint8 > X = zeros([rows, cols, 3],'uint8'); %must use 'uint8', if double then > the range is [0,1] > whos X; > sizeOf2DArray = [rows cols]; > for ib=1:4 > X(:,:,ib) = ReturnUint8Array(sizeOf2DArray); > end > whos X; > max(max(X)) > > % Try it with X being declared as uint8 > XX = zeros([rows, cols, 3],'double'); %must use 'uint8', if double > then the range is [0,1] > whos XX; > for ib=1:4 > XX(:,:,ib) = ReturnUint8Array(sizeOf2DArray); > end > whos XX; > max(max(XX)) > return; > %-------------------------------------------------------------------------- > function uint8Array = ReturnUint8Array(inputArray) > realArray = 255 * rand(inputArray(1), inputArray(2)); > uint8Array = uint8(realArray); > return; > > %-------------------------------------------------------------------------- > Even if you're using multibandread() (instead of the ReturnUint8Array > in my simple little demo), the help for multibandread() says "a > precision of 'uint8=>uint8' (or '*uint8') will return the data as a > UINT8 array." meaning it can go from 0-255. > > So I still don't understand why you say "then all digital counts go to > 1. " when you declared X as uint8. That should not happen. But > whatever, as long as you got it working.... I copy your program and save it as test.m. Then run it. It's quite weird. I don't find any variables in Workspace, although I can see the X and XX after 'whos'. Then I save function uint8Array as a file 'ReturnUint8Array.m'. Then I save 'test.m' with 'function test' appearing in the beginning. Then run 'test.m'. I don't see any variables, either. Then I delete 'function test' appearing in the beginning of 'test.m'. Then run it. All the variables show. Do I miss something very basic here? I insert 'imtool' after line 16 and 25. Then run 'test.m'. I see all the variables and also pop up two image tool windows. Then I saw only XX, but no X. Then I click File-> 'import from workspace' in this window. click XX as my image. Use 'Tool'->'Pixel region'. Their values are all 1 for RGB. Thank you very much. Mike
From: Mike on 31 Jan 2010 22:42 On Jan 30, 2:54 pm, Mike <sulfate...(a)gmail.com> wrote: > On Jan 30, 10:20 am, ImageAnalyst <imageanal...(a)mailinator.com> wrote: > > > > > I don't agree Mike. If you have a function that returns a uint8 in > > the range 0-255, and accept it into a variable that was previously > > declared as a 3D uint 8 array (even if you declared it as 3 planes but > > assigned 4 planes as you did), then the result will be a uint8 array > > in the range 0-255. If you do the same thing but the previously > > initialized variable was a 3D double array, then the result is > > converted into a double array with the range 0-255. There is no > > scaling of 0-255 into 0-1 in either case. Moreover, if X is a double > > array there is nothing that says it has to be in the range 0-1 like > > you say. It can take any value from -1.7977e+308 to +1.7977e+308. > > Here's proof: > > %-------------------------------------------------------------------------- > > function test > > clc; > > close all; > > clear all; > > workspace; % Display workspace panel. > > > rows = 500; > > cols = 500; > > % Try it with X being declared as uint8 > > X = zeros([rows, cols, 3],'uint8'); %must use 'uint8', if double then > > the range is [0,1] > > whos X; > > sizeOf2DArray = [rows cols]; > > for ib=1:4 > > X(:,:,ib) = ReturnUint8Array(sizeOf2DArray); > > end > > whos X; > > max(max(X)) > > > % Try it with X being declared as uint8 > > XX = zeros([rows, cols, 3],'double'); %must use 'uint8', if double > > then the range is [0,1] > > whos XX; > > for ib=1:4 > > XX(:,:,ib) = ReturnUint8Array(sizeOf2DArray); > > end > > whos XX; > > max(max(XX)) > > return; > > %-------------------------------------------------------------------------- > > function uint8Array = ReturnUint8Array(inputArray) > > realArray = 255 * rand(inputArray(1), inputArray(2)); > > uint8Array = uint8(realArray); > > return; > > > %-------------------------------------------------------------------------- > > Even if you're using multibandread() (instead of the ReturnUint8Array > > in my simple little demo), the help for multibandread() says "a > > precision of 'uint8=>uint8' (or '*uint8') will return the data as a > > UINT8 array." meaning it can go from 0-255. > > > So I still don't understand why you say "then all digital counts go to > > 1. " when you declared X as uint8. That should not happen. But > > whatever, as long as you got it working.... > > I copy your program and save it as test.m. > Then run it. It's quite weird. I don't find any variables in > Workspace, > although I can see the X and XX after 'whos'. > > Then I save function uint8Array as a file 'ReturnUint8Array.m'. > Then I save 'test.m' with 'function test' appearing in the beginning. > Then run 'test.m'. > I don't see any variables, either. > Then I delete 'function test' appearing in the beginning of 'test.m'. > Then run it. > All the variables show. > Do I miss something very basic here? > > I insert 'imtool' after line 16 and 25. Then run 'test.m'. > I see all the variables and also pop up two image tool windows. > Then I saw only XX, but no X. Then I click File-> 'import from > workspace' in this window. > click XX as my image. Use 'Tool'->'Pixel region'. Their values are > all 1 for RGB. > > Thank you very much. > > Mike Just repost it again, details are in the above. In short, when using imtool to import an image of 'double', the gray levels of RGB are all 1. Mike
From: Steven Lord on 31 Jan 2010 22:47 "Mike" <sulfateion(a)gmail.com> wrote in message news:481269ef-4134-4f21-8e68-c2bbdb52645b(a)m24g2000prn.googlegroups.com... On Jan 30, 10:20 am, ImageAnalyst <imageanal...(a)mailinator.com> wrote: > I don't agree Mike. If you have a function that returns a uint8 in > the range 0-255, and accept it into a variable that was previously > declared as a 3D uint 8 array (even if you declared it as 3 planes but > assigned 4 planes as you did), then the result will be a uint8 array > in the range 0-255. If you do the same thing but the previously > initialized variable was a 3D double array, then the result is > converted into a double array with the range 0-255. There is no > scaling of 0-255 into 0-1 in either case. Moreover, if X is a double > array there is nothing that says it has to be in the range 0-1 like > you say. It can take any value from -1.7977e+308 to +1.7977e+308. > Here's proof: > %-------------------------------------------------------------------------- > function test > clc; > close all; > clear all; Technically, the CLEAR ALL here is unnecessary, although I assume it's there to convince you that this function is starting from a clean slate. > workspace; % Display workspace panel. *snip most of ImageAnalyst's code* > I copy your program and save it as test.m. > Then run it. It's quite weird. I don't find any variables in > Workspace, > although I can see the X and XX after 'whos'. That's correct. Functions each have their own workspaces that are destroyed after the functions are finished executing. Unless you return a variable from the function as an output argument (or use one of a few "advanced maneuvers" that I'm not going to get into here) they will not be available in the calling function's workspace (or the base workspace, if you called the function from the command line.) Read this section of the documentation for more information about functions and function workspaces. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f7-38012.html Script files behave differently; you can read about them in that section of the documentation as well. > Then I save function uint8Array as a file 'ReturnUint8Array.m'. > Then I save 'test.m' with 'function test' appearing in the beginning. > Then run 'test.m'. > I don't see any variables, either. > Then I delete 'function test' appearing in the beginning of 'test.m'. > Then run it. > All the variables show. > Do I miss something very basic here? Yes; read above. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: read certain number in a text file Next: FCM using Image |