Dear all,
I have found similar questions to mine, but nothing quite the same. I have very little experience with ImageJ and could not find an answer to my question in the documentation and thought this may be a place to start. If I am in the wrong place, please let me know. I have two questions: 1) problem importing ascii numbers I am trying to transfer some data from one software tool to another, where the second requires a 3Dimage file in binary format (unsigned short integers) as its input. I have a 3D voxel space of 100x100x100 voxels, which I essentially have full control over and can (in theory) write to any format I want (or imageJ needs). ImageJ was recommended to me as being able to load in ascii data and write out the 3D image file. I have reduced my voxel map to a very simple case of a straight line for debugging purposes. So I export my voxel space into a list of 1 million decimals either 0 or 9: 0 0 0 (...) 9 (...) 0 If I load this into imageJ using File>Import>Raw data.. and set up the formatting (100pixelsx100pixelsx100slices), then I can see my line where I expect it to be. However if I replace the 9's with 10's, the image seems to become a mess and I dont see my line anymore. I am guessing I need to add some space delimiter. I have tried 0,0,0 and 0 "\t" 0 etc, but cant find what is correct. If anyone can advise me how best to change my format, this will be very helpful. 2) Saving the imported data to 3D image Let's say I go back to the 9's and I can see my data no problem. Then I want to save it, I have been advised to save it as raw data, unsigned short int in binary format. But using File>Save As> Raw data , seems to just give me a list of integers again, when I need a binary option. Does this exist somewhere? These feel like basic questions to me, but I could not find what I wanted in the user guide. Perhaps someone can also recommend further documentation. Many thanks in advance, Dave |
Hi Dave,
if you want to import your data in ImageJ as raw, don't write ASCII. Instead write bytes, without any delimiters in between, and use 8-bit raw import in ImageJ. If your software can't do that, if it can only write strings (text), no raw bytes, then you should convert the pixel values to characters by some function that gets the ascii character from the character code, and use the pixel value as character code. Conversion to text won't work if your software uses the 0 byte as string terminator (many C programs do). Also, beware of software translating higher values (>127) to Unicode with more than 1 byte. What you currently do: ImageJ reads the ascii code for each pixel. If you read bytes, the pixels written as "0" will be read as character code 48 (0x30 hex), "1" will become 49, and "9" becomes 57. You would have to write a colon ":" for 58, a semicolon ";" for 59, etc. For exporting as unsigned short int, simply convert your image to "16- bit". Save As>Raw Data should do the job, but you have to try whether you need little or big endian format. You can set this in Edit>Options>Input/Output, "Save tiff&raw in Intel byte order" Michael ________________________________________________________________ On 18 Apr 2011, at 16:30, DavidOxley2 wrote: > Dear all, > I have found similar questions to mine, but nothing quite the same. > I have > very little experience with ImageJ and could not find an answer to my > question in the documentation and thought this may be a place to > start. If I > am in the wrong place, please let me know. > I have two questions: > > 1) problem importing ascii numbers > I am trying to transfer some data from one software tool to > another, where > the second requires a 3Dimage file in binary format (unsigned short > integers) as its input. > I have a 3D voxel space of 100x100x100 voxels, which I essentially > have full > control over and can (in theory) write to any format I want (or imageJ > needs). ImageJ was recommended to me as being able to load in ascii > data and > write out the 3D image file. > I have reduced my voxel map to a very simple case of a straight > line for > debugging purposes. So I export my voxel space into a list of 1 > million > decimals either 0 or 9: > 0 > 0 > 0 > (...) > 9 > (...) > 0 > > If I load this into imageJ using File>Import>Raw data.. and set up the > formatting (100pixelsx100pixelsx100slices), then I can see my line > where I > expect it to be. However if I replace the 9's with 10's, the image > seems to > become a mess and I dont see my line anymore. I am guessing I need > to add > some space delimiter. I have tried 0,0,0 and 0 "\t" 0 etc, but cant > find > what is correct. > If anyone can advise me how best to change my format, this will be > very > helpful. > > 2) Saving the imported data to 3D image > Let's say I go back to the 9's and I can see my data no problem. > Then I want > to save it, I have been advised to save it as raw data, unsigned > short int > in binary format. But using File>Save As> Raw data , seems to just > give me a > list of integers again, when I need a binary option. Does this exist > somewhere? > > These feel like basic questions to me, but I could not find what I > wanted in > the user guide. Perhaps someone can also recommend further > documentation. > > Many thanks in advance, > > > Dave > > > -- > View this message in context: http://imagej.588099.n2.nabble.com/ > Importing-data-from-ascii-format-tp6283855p6283855.html > Sent from the ImageJ mailing list archive at Nabble.com. |
Hi Dave,
In addition to what Michael said, please note that there is a File > Import > Text Image command that does essentially what you want. It works if you write a text file with a space delimiter between pixels, and newlines between rows. However, it won't support multiple image planes, as far as I know. You could write each plane to its own text file and then batch import them via a macro. -Curtis On Tue, Apr 19, 2011 at 3:22 AM, Michael Schmid <[hidden email]>wrote: > Hi Dave, > > if you want to import your data in ImageJ as raw, don't write ASCII. > Instead write bytes, without any delimiters in between, and use 8-bit raw > import in ImageJ. > If your software can't do that, if it can only write strings (text), no raw > bytes, then you should convert the pixel values to characters by some > function that gets the ascii character from the character code, and use the > pixel value as character code. > Conversion to text won't work if your software uses the 0 byte as string > terminator (many C programs do). Also, beware of software translating higher > values (>127) to Unicode with more than 1 byte. > > What you currently do: ImageJ reads the ascii code for each pixel. If you > read bytes, the pixels written as "0" will be read as character code 48 > (0x30 hex), "1" will become 49, and "9" becomes 57. You would have to write > a colon ":" for 58, a semicolon ";" for 59, etc. > > For exporting as unsigned short int, simply convert your image to "16-bit". > Save As>Raw Data should do the job, but you have to try whether you need > little or big endian format. You can set this in Edit>Options>Input/Output, > "Save tiff&raw in Intel byte order" > > Michael > ________________________________________________________________ > > > On 18 Apr 2011, at 16:30, DavidOxley2 wrote: > > Dear all, >> I have found similar questions to mine, but nothing quite the same. I have >> very little experience with ImageJ and could not find an answer to my >> question in the documentation and thought this may be a place to start. If >> I >> am in the wrong place, please let me know. >> I have two questions: >> >> 1) problem importing ascii numbers >> I am trying to transfer some data from one software tool to another, where >> the second requires a 3Dimage file in binary format (unsigned short >> integers) as its input. >> I have a 3D voxel space of 100x100x100 voxels, which I essentially have >> full >> control over and can (in theory) write to any format I want (or imageJ >> needs). ImageJ was recommended to me as being able to load in ascii data >> and >> write out the 3D image file. >> I have reduced my voxel map to a very simple case of a straight line for >> debugging purposes. So I export my voxel space into a list of 1 million >> decimals either 0 or 9: >> 0 >> 0 >> 0 >> (...) >> 9 >> (...) >> 0 >> >> If I load this into imageJ using File>Import>Raw data.. and set up the >> formatting (100pixelsx100pixelsx100slices), then I can see my line where I >> expect it to be. However if I replace the 9's with 10's, the image seems >> to >> become a mess and I dont see my line anymore. I am guessing I need to add >> some space delimiter. I have tried 0,0,0 and 0 "\t" 0 etc, but cant find >> what is correct. >> If anyone can advise me how best to change my format, this will be very >> helpful. >> >> 2) Saving the imported data to 3D image >> Let's say I go back to the 9's and I can see my data no problem. Then I >> want >> to save it, I have been advised to save it as raw data, unsigned short int >> in binary format. But using File>Save As> Raw data , seems to just give me >> a >> list of integers again, when I need a binary option. Does this exist >> somewhere? >> >> These feel like basic questions to me, but I could not find what I wanted >> in >> the user guide. Perhaps someone can also recommend further documentation. >> >> Many thanks in advance, >> >> >> Dave >> >> >> -- >> View this message in context: >> http://imagej.588099.n2.nabble.com/Importing-data-from-ascii-format-tp6283855p6283855.html >> Sent from the ImageJ mailing list archive at Nabble.com. >> > |
Free forum by Nabble | Edit this page |