Front Page › Forums › BioMap › Excel to Analyze Conversion
- This topic has 1 reply, 2 voices, and was last updated 12 years, 10 months ago by
Dodge Baluya.
-
AuthorPosts
-
November 4, 2011 at 1:38 pm #1390
Markus Stoeckli
ModeratorI thought this could be helpful also to others. This code runs in Excel and exports data from a 1536-well plate to analyze format. You may use this code as basis for your project… but if you do, please share it with us in this forum.
[code]Option Explicit
‘image dimensions
Private XPoints As Long
Private YPoints As Long
Private DataFile As String
Private VialSize As Single‘images
Private NumberOfImages As Long
Private ImageData() As Single
Private ImageIndex As IntegerPrivate Type uAnaHdr
sizeof_hdr As Long ‘0+4
data_type As String * 10 ‘4+10
db_name As String * 18 ’14+18
extents As Long ’32+4
session_error As Integer ’36+2
regular As Byte ’38+1
hkey_un0 As Byte ’39+1
End Type ‘total 40 bytesPrivate Type uAnaDim
dims(7) As Integer ‘0+16
unused8 As Integer ’16+2
unused9 As Integer ’18+2
unused10 As Integer ’20+2
unused11 As Integer ’22+2
unused12 As Integer ’24+2
unused13 As Integer ’26+2
unused14 As Integer ’28+2
datatype As Integer ’30+2
bitpix As Integer ’32+2
dim_un0 As Integer ’34+2
pixdim(7) As Single ’36+32
vox_offset As Single ’68+4
funused1 As Single ’72+4
funused2 As Single ’76+4
funused3 As Single ’80+4
cal_max As Single ’84+4
cal_min As Single ’88+4
compressed As Single ’92+4
verified As Single ’96+4
glmax As Long ‘100+4
glmin As Long ‘104+4
End Type ‘total 108 bytesPrivate Type uAnaHist
descrip As String * 80 ‘0+80
aux_files As String * 24 ’80+24
orient As Byte ‘104+1
orginator As String * 10 ‘105+10
generated As String * 10 ‘115+10
scannum As String * 10 ‘125+10
patient_id As String * 10 ‘135+10
exp_date As String * 10 ‘145+10
exp_time As String * 10 ‘155+10
hist_un0 As String * 3 ‘165+3
views As Long ‘168+4
vols_added As Long ‘172+4
start_field As Long ‘176+4
field_skip As Long ‘180+4
omax As Long ‘184+4
omin As Long ‘188+4
smax As Long ‘192+4
smin As Long ‘196+4
End Type ‘total 200 bytesPrivate Type uAnaDsr
hk As uAnaHdr ‘0+40
dime As uAnaDim ’40+108
hist As uAnaHist ‘148+200
End Type ‘total 348 bytes‘Acceptable values for datatype
Private Const DT_NONE = 0
Private Const DT_UNKNOWN = 0
Private Const DT_BINARY = 1
Private Const DT_UNSIGNED_CHAR = 2
Private Const DT_SIGNED_SHORT = 4
Private Const DT_SIGNED_INT = 8
Private Const DT_FLOAT = 16
Private Const DT_COMPLEX = 32
Private Const DT_DOUBLE = 64
Private Const DT_RGB = 128
Private Const DT_ALL = 255Private Sub WriteAnalyzeHeader()
On Error Resume Next
Dim ah As uAnaDsr
ah.hk.sizeof_hdr = 348
ah.hk.extents = 16384
ah.hk.regular = Asc(“r”)ah.dime.dims(0) = 4 ‘4 dimensions
ah.dime.dims(1) = 1
ah.dime.dims(2) = XPoints
ah.dime.dims(3) = YPoints
ah.dime.dims(4) = 1
ah.dime.pixdim(0) = 1
ah.dime.pixdim(1) = 1
ah.dime.pixdim(1) = VialSize
ah.dime.pixdim(2) = 1
ah.dime.pixdim(2) = VialSize
ah.dime.pixdim(3) = 1
ah.dime.datatype = DT_FLOAT
ah.dime.bitpix = 16On Error Resume Next
Open Left(DataFile, Len(DataFile) – 3) & “hdr” For Binary As 7
Put 7, , ah
Close 7
End SubPrivate Sub WriteMassFile()
On Error Resume Next
Dim dummy As Single
dummy = 1
Open Left(DataFile, Len(DataFile) – 3) & “t2m” For Binary As 2
Put 2, , dummy
Close 2
End SubSub SaveImage()
Dim DataRange As Variant
Dim row As Long, col As Long
Dim ImgData As SingleVialSize = 2.25 ’96: 9 mm, 384: 4.5 mm, 1536: 2.25 mm
With Application
‘ Set File Name to selected File
DataFile = .GetSaveAsFilename(“”, “Analyze (*.img),*.img”)
‘ Reset Start Drive/Path
‘ChDrive (Left(.DefaultFilePath, 1))
‘ChDir (.DefaultFilePath)
End WithIf Len(DataFile) = 0 Then Exit Sub
DataRange = Selection
XPoints = UBound(DataRange, 2)
YPoints = UBound(DataRange)Open DataFile For Binary As 1
For row = YPoints To 1 Step -1
For col = 1 To XPoints
ImgData = DataRange(row, col)
Put 1, , ImgData
Next
Next
Close 1
WriteAnalyzeHeader
WriteMassFileEnd Sub
[/code]
November 4, 2011 at 6:56 pm #1391Dodge Baluya
ParticipantThanks for this helpful code. I am actually interested to get some intensity data w/ position out of .img format to excel (or some other format) in order to do some data processing. Same concerns as the person who posted “Re:Export raw data from image”
This code would serve as a starting point. -
AuthorPosts
- You must be logged in to reply to this topic.