Skip to content

Commit

Permalink
fixed 16-bit TIFFs, added error handling kludge
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Apr 2, 2013
1 parent 27565ca commit 5326f22
Show file tree
Hide file tree
Showing 5 changed files with 3,530 additions and 54 deletions.
2 changes: 1 addition & 1 deletion filelist/filesettings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IMG_LOCS = {"pixis":"C:\\Dropbox\\imgpixis\\","pflyold":"C:\\Dropbox\\imgpflyold"}
IMG_LOCS = {"pixis":"C:\\Dropbox\\imgpixis\\","pflyold":"C:\\Dropbox\\imgpflyold", "pfly":"C:\\Dropbox\\imgpfly", "andor":"C:\\Dropbox\\imgandor"}
RL_LOCS = {"crunlogs":"C:\\runlogs\\"}
STATIC_DIR = "./static/"
#THUMB_DIR = "C:\\thumb\\"
Expand Down
46 changes: 25 additions & 21 deletions filelist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,31 @@ def makeRawFrames(self):
def deleteProcFrames(self):
ProcessedFrame.objects.filter(sourceimage=self).delete()
def ProcessImage(self):
for method in self.imgtype.methods.all():
procmodule = __import__(method.modulename)
reload(procmodule)
procmethod = getattr(procmodule, method.name)
argdict = {}
for param in TypeParameters.objects.filter(imagetype=self.imgtype, methodargument__method=method):
argdict[param.methodargument.name]=param.value
for ROIparam in TypeROI.objects.filter(imagetype=self.imgtype, methodargument__method=method):
argdict[ROIParam.methodargument.name]=ROIparam.ToDict()
result=procmethod(self.path, **argdict)
if not isinstance(result,tuple):
result = (result,)
for ii in range(len(result)):
if isarray(result[ii]):
filename=os.path.splitext(os.path.split(self.path)[1])[0]+'_'+method.name+'_'+str(ii)+'.png'
newrecord = ProcessedFrame(sourceimage=self, method=method, framenumber=ii)
newrecord.saveframe(result[ii], filename, cmin=0, cmax=1)
newrecord.save()
else:
newrecord = ProcessedValue(sourceimage=self, method=method, value=float(item[ii]), index=ii)
newrecord.save()
if self.imgtype:
for method in self.imgtype.methods.all():
procmodule = __import__(method.modulename)
reload(procmodule)
procmethod = getattr(procmodule, method.name)
argdict = {}
for param in TypeParameters.objects.filter(imagetype=self.imgtype, methodargument__method=method):
argdict[param.methodargument.name]=param.value
for ROIparam in TypeROI.objects.filter(imagetype=self.imgtype, methodargument__method=method):
argdict[ROIParam.methodargument.name]=ROIparam.ToDict()
try:
result=procmethod(self.path, **argdict)
if not isinstance(result,tuple):
result = (result,)
for ii in range(len(result)):
if isarray(result[ii]):
filename=os.path.splitext(os.path.split(self.path)[1])[0]+'_'+method.name+'_'+str(ii)+'.png'
newrecord = ProcessedFrame(sourceimage=self, method=method, framenumber=ii)
newrecord.saveframe(result[ii], filename, cmin=0, cmax=1)
newrecord.save()
else:
newrecord = ProcessedValue(sourceimage=self, method=method, value=float(item[ii]), index=ii)
newrecord.save()
except:
pass
def getClosestSequence(self):
sql = "SELECT * FROM filelist_runloginfo ORDER BY ABS(TIMESTAMPDIFF(SECOND, time,'" + self.time.strftime('%Y-%m-%d %H:%M:%S') + "')-sequenceduration) LIMIT 1"
for retrunlog in RunLogInfo.objects.raw(sql):
Expand Down
56 changes: 26 additions & 30 deletions filelist/odysseus/imageio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

import os

import numpy as np
import scipy as sp
# if available, use Zach Pincus' pil_lite which has correct 16-bit TIFF loading
Expand All @@ -18,6 +19,7 @@
except ImportError:
import Image
#import tables
import tifffile


def list_of_frames(img_name):
Expand All @@ -26,21 +28,17 @@ def list_of_frames(img_name):
Details are as described in the imgimport_intelligent docstring.
"""

img = Image.open(img_name)
img = tifffile.TiffFile(img_name)
#img = Image.open(img_name)
imglist = []

try:
for i in xrange(8):
if img.mode == 'I':
imdata = np.asarray(img, dtype=np.int16)
else:
imdata = np.asarray(img, dtype=np.float32)
# fix 3-channel TIFF images
for i in range(np.size(img)):
imdata = img[i].asarray()
imdata = imdata.astype(np.float32)
if np.rank(imdata)==3:
imdata = imdata[:,:,0] + 256*imdata[:,:,1] + 65536*imdata[:,:,2]
imglist.append(imdata)
img.seek(i+1) # next frame
except EOFError:
pass

Expand All @@ -49,23 +47,6 @@ def list_of_frames(img_name):
else:
return imglist

def trans_nonorm(img_name):
raw_frames=imgimport_intelligent(img_name)

pwa = raw_frames[:, :, 0]
pwoa = raw_frames[:, :, 1]
df = raw_frames[:, :, 2]

nom = pwa - df
den = pwoa - df

nom = np.where(nom<1, 1, nom)
den = np.where(den<1, 1, den)

transimg = nom.astype(float)/den

return transimg/1.35


def imgimport_intelligent(img_name, foo=3, bar=4, roi_baz=[12,24,56,78]):
"""Opens an image file containing one or more frames
Expand Down Expand Up @@ -131,9 +112,7 @@ def imgimport_intelligent(img_name, foo=3, bar=4, roi_baz=[12,24,56,78]):

transimg = nom.astype(float)/den

return 5


return img_array

def import_rawframes(img_name):
"""Opens an image file containing three frames
Expand Down Expand Up @@ -328,12 +307,29 @@ def load_hdfimage(fname, dirname=None, ext_replace=True):
pwa = np.asarray(h5file.root.rawframes.pwa)
pwoa = np.asarray(h5file.root.rawframes.pwoa)
df = np.asarray(h5file.root.rawframes.df)
imgarray = np.dstack([pwa, pwao, df])
imgarray = np.dstack([pwa, pwoa, df])
return imgarray

finally:
h5file.close()

def trans_nonorm(img_name):
raw_frames=imgimport_intelligent(img_name)

pwa = raw_frames[:, :, 0]
pwoa = raw_frames[:, :, 1]
df = raw_frames[:, :, 2]

nom = pwa - df
den = pwoa - df

nom = np.where(nom<1, 1, nom)
den = np.where(den<1, 1, den)

transimg = nom.astype(float)/den

return transimg/1.35


def convert_xcamera_to_hdf5(imglist, ext='xraw'):
"""Convert every file in imglist to an hdf5 file.
Expand Down
Loading

0 comments on commit 5326f22

Please sign in to comment.