Exemplo n.º 1
0
def test_zero_image_nodna():
    img=pyslic.Image()
    img.channeldata['protein'] = numpy.zeros((100,100))
    img.loaded=True
    img.channels['protein']='<special>'
    F=pyslic.computefeatures(img,'mcell')
    assert F.size == 31
    assert numpy.isnan(F).sum() == 0

    F=pyslic.computefeatures(img,['img'])
    assert F.size == 8
    assert numpy.isnan(F).sum() == 0
Exemplo n.º 2
0
def field_features(im):
    import pyslic
    img = pyslic.Image()
    img.channels = {'protein':'<protein>', 'dna':'<dna>'}
    img.channeldata = {'protein':im.get("protein"), 'dna':im.get('dna')}
    im.unload()
    img.loaded = True
    return pyslic.computefeatures(img, 'field-dna+')
def compute_field_features(img, scale, F):
    try:
        img.scale=scale
        print img.scale
        with pyslic.image.loadedimage(img):
            return pyslic.computefeatures(img, 'field-dna+')
    except:
        return None
Exemplo n.º 4
0
def test_featinfolen():
    imgdata = basedir+'/data/protimg.jp2'
    imgdata = pyslic.image.io.readimg(imgdata)
    img = pyslic.Image()
    img.channeldata['protein'] = imgdata
    img.loaded = True
    img.channels['protein']='<special>'
    assert len(pyslic.computefeatures(img,'SLF33')) == len(pyslic.features.featinfo.get_names('SLF33'))
Exemplo n.º 5
0
def test_negative_image():
    img=pyslic.Image()
    img.channeldata['protein'] = -numpy.ones((10,10))
    img.channeldata['dna'] = -numpy.ones((10,10))
    img.loaded=True
    img.channels['protein']='<special>'
    img.channels['dna']='<special>'
    F=pyslic.computefeatures(img,'SLF7dna')
    assert F.size == 90
    assert numpy.isnan(F).sum() == 0
Exemplo n.º 6
0
def test_tas():
    img=basedir+'/data/protimg.jp2'
    img=pyslic.image.io.readimg(img)

    IMG=pyslic.Image()
    IMG.channeldata['protein']=img
    IMG.loaded=True
    IMG.channels['protein']='<special>'
    assert len(pyslic.features.tas.tas(img)) == 2*3*9
    assert len(pyslic.features.tas.pftas(img)) == 2*3*9

    assert numpy.all(pyslic.features.tas.tas(img) == pyslic.computefeatures(IMG,['tas']))
def make_content_db(basedir,scale):
    dataset=[]
    pattern_iid_dict={}
    for x in os.listdir(basedir):
        pattern_iid_dict[x]=[]
        for y in os.listdir(basedir+x):
            directory=basedir+x+'/'+y
            print directory
            imgs=auto_detect_load(directory)
            for img in imgs:
                img.scale=scale
                img.load()
                field_features=pyslic.computefeatures(img,'field-dna+')
                img_id=os.path.basename(img.channels['protein']).replace('.bmp','_10x')
                dataset.append([img_id,1,list(field_features)])
                pattern_iid_dict[x].append(img_id)

    pickle.dump(dataset,open(INT_DIR+'dataset_'+resolution+'.pkl','wb'))
    pickle.dump(pattern_iid_dict,open(INT_DIR+'pattern_iid_dict_'+resolution+'.pkl','wb'))
print os.getcwd()
import sys
sys.path.append(os.getcwd()+'/scripts')
import tif2array
import pyslic

for key, val in sys.modules.items():
      if 'pyslic' in key:
            print key,val

INPUT_DIR='./images/ASCB_images/'
OUTPUT_DIR='./intermediate_results/ASCB_features/'

if not os.path.isdir(OUTPUT_DIR):
      os.makedirs(OUTPUT_DIR)

image_res_dict=pickle.load(open('scripts/image_res_dict.pkl','rb'))
for imageid, res in image_res_dict.items():
      filename=INPUT_DIR+str(imageid)+'.tiff'
      if os.path.isfile(filename):
          img_read=tif2array.tif2array(filename,True)
          img=pyslic.Image()
          img.channeldata['protein']=img_read[:,:,0]
          img.channels['protein']=filename
          img.scale=res
          feats=pyslic.computefeatures(img,'slf33')
          if feats is not None:
              pickle.dump(feats,open(OUTPUT_DIR+str(imageid)+'.pkl','wb'))

                                            
Exemplo n.º 9
0
import numpy as np
MURPHYLAB_HELA2D_PATH = '/home/luispedro/work/murphylab/images/hela-2d/'
print r'''\
This is only to be run if you have got the Murphylab images installed at
    %s

Otherwise, you will get errors!
''' % MURPHYLAB_HELA2D_PATH
import pyslic
imgs = pyslic.image.io.dirtransversal.dirtransversal(MURPHYLAB_HELA2D_PATH)
labels = np.array([img.label for img in imgs])
features = pyslic.computefeatures(imgs, 'SLF7DNA')
np.savez('murphylab.npz', features=features, labels=labels)
Exemplo n.º 10
0
import numpy as np
MURPHYLAB_HELA2D_PATH = '/home/luispedro/work/murphylab/images/hela-2d/'
print(r'''\
This is only to be run if you have got the Murphylab images installed at
    {}

Otherwise, you will get errors!
'''.format(MURPHYLAB_HELA2D_PATH))
import pyslic
imgs = pyslic.image.io.dirtransversal.dirtransversal(MURPHYLAB_HELA2D_PATH)
labels = np.array([img.label for img in imgs])
features = pyslic.computefeatures(imgs, 'SLF7DNA')
np.savez('murphylab.npz', features=features, labels=labels)
Exemplo n.º 11
0
			for filename in filenames:
				filename = path.join( filepath, filename )
				print filename
				[basename, extension] = path.splitext(filename)

				if extension == '.tif':
					features_filename = basename + '.pkl'
					pixels = Image.open(filename)
					pixels = numpy.array(pixels)
				
					#make pyslic image container
        				img=pyslic.Image()
        				img.label=basename
        				img.scale=0.237

        				img.channels[ 'protein' ] = 0
					img.channeldata[ 'protein' ] = pixels

        				img.loaded=True
					features = pyslic.computefeatures(img,'field+')
					image = {}
					image['pixels']=pixels
					image['scale']=img.scale
					image['label']=img.label
					image['feature_set']='SLF33'
					image['feature_ids']=feature_ids
					image['features']=features
				
					pickle.dump(image, open(features_filename,'w'))
		chdir( '../' )					
Exemplo n.º 12
0
def calculate( conn, iid, scale=1, set="slf33", field=True, rid=None, pixels=0, channels=[], zslice=0, timepoint=0, threshold=None, debug=False ):
    '''
    Calculates and returns a feature ids vector, a feature vector and the output scale given a valid
    image identification (iid). It currently can calculate SLF33, SLF34, SLF35 and SLF36.

    This method will try to retrieve the resolution of the image from the annotations. 

    If the method is unable to connect to the OMERO.server, then the method will return None.

    If the method doesn't find an image associated with the given image id (iid), then the method will return None.

    For detailed outputs, set debug flag to True.
    
    :param conn: connection
    :type conn: BlitzGateway connection
    :param iid: image id
    :type iid: long
    :param scale: image scale
    :type scale: double
    :param set: feature set name
    :type set: string
    :param field: true if field features, false otherwise
    :type field: boolean
    :param rid: region id
    :type rid: long
    :param pixels: pixel index associated with the image
    :type pixels: integer
    :param channels: list of channel indices
    :type channels: list of integers
    :param zslice: zslice index
    :type zslice: integer
    :param timepoint: time point index
    :type timepoint: integer
    :param threshold: image size threshold value
    :type threshold: integer
    :param debug: debug flag
    :type debug: boolean
    :rtype: a list of feature ids, a feature vector and the scale at which the features where calculated
    '''
   
    if not conn.isConnected():
        raise PyslidException("Unable to connect to OMERO.server")

    if not pyslid.utilities.hasImage( conn, iid ):
        raise PyslidException("No image found with the given image id:%s", iid)
    #check input arguments
    image = conn.getObject("Image", long(iid) )

    if image is None:
        raise PyslidException("Unable to retrieve image with iid:%s", iid)
    else:
        try:
            #if threshold is empty use default value
            if threshold == None:
                threshold = 10*1024;

            #check if image size is greater than threshold value
            #icaoberg 19/02/2013
            if image.getPixelSizeY() > threshold:
                raise PyslidException("Image size is greater than threshold value")
            #icaoberg 19/02/2013
            elif image.getPixelSizeY() > threshold:
                raise PyslidException("Image size is greater than threshold value")
            else:
                #set scale value
                imgScale = pyslid.image.getScale( conn, iid, debug )
                imgScale = imgScale[0]        
        except:
            #if no scale value is present, pyslic will set a scale value of .23
            #to avoid that we prevent feature calculation
            raise PyslidException("Unable to retrieve resolution or resolution was not set")

    #set resolution based on the scale
    print 'scale:%f imgScale:%f' %(scale, imgScale)
    inputScale = scale
    if scale < 0.33 and abs(scale - imgScale)>0.001 :
         scale = imgScale
    elif scale < 0.67 and abs(scale - imgScale*2)>0.001:
         scale = imgScale*2
    else:
         scale = imgScale*4
    print 'Forcing pyslid calculated scale from %f to input scale %f' % (
        scale, inputScale)
    scale = inputScale

    feature_ids = ["SLF27.66","SLF27.67","SLF27.68","SLF27.69","SLF27.70","SLF27.71","SLF27.72","SLF27.73","SLF27.74","SLF27.75","SLF27.76","SLF27.77","SLF27.78","SLF33.37","SLF33.38","SLF33.39","SLF33.40","SLF33.41","SLF33.42","SLF33.43","SLF33.44","SLF33.45","SLF33.46","SLF33.47","SLF33.48","SLF33.49","SLF33.50","SLF33.51","SLF33.52","SLF33.53","SLF33.54","SLF33.55","SLF33.56","SLF33.57","SLF33.58","SLF33.59","SLF33.60","SLF33.61","SLF33.62","SLF33.63","SLF33.64","SLF33.65","SLF33.66","SLF33.67","SLF33.68","SLF33.69","SLF33.70","SLF33.71","SLF33.72","SLF33.73","SLF33.74","SLF33.75","SLF33.76","SLF33.77","SLF33.78","SLF33.79","SLF33.80","SLF33.81","SLF33.82","SLF33.83","SLF33.84","SLF33.85","SLF33.86","SLF33.87","SLF33.88","SLF33.89","SLF33.90","SLF33.91","SLF33.92","SLF33.93","SLF33.94","SLF33.95","SLF33.96","SLF33.97","SLF33.98","SLF33.99","SLF33.100","SLF33.101","SLF33.102","SLF33.103","SLF33.104","SLF33.105","SLF33.106","SLF33.107","SLF33.108","SLF33.109","SLF33.110","SLF33.111","SLF33.112","SLF33.113","SLF33.114","SLF27.1","SLF27.2","SLF27.3","SLF27.4","SLF27.5","SLF27.89","SLF27.90","SLF27.9","SLF27.10","SLF27.11","SLF27.12","SLF27.13","SLF27.80","SLF27.81","SLF27.82","SLF27.83","SLF27.84","SLF27.79","SLF31.1","SLF31.2","SLF31.3","SLF31.4","SLF31.5","SLF31.6","SLF31.7","SLF31.8","SLF31.9","SLF31.10","SLF31.11","SLF31.12","SLF31.13","SLF31.14","SLF31.15","SLF31.16","SLF31.17","SLF31.18","SLF33.1","SLF33.2","SLF33.3","SLF33.4","SLF33.5","SLF33.6","SLF33.7","SLF33.8","SLF33.9","SLF33.19","SLF33.20","SLF33.21","SLF33.22","SLF33.23","SLF33.24","SLF33.25","SLF33.26","SLF33.27","SLF33.10","SLF33.11","SLF33.12","SLF33.13","SLF33.14","SLF33.15","SLF33.16","SLF33.17","SLF33.18","SLF33.28","SLF33.29","SLF33.30","SLF33.31","SLF33.32","SLF33.33","SLF33.34","SLF33.35","SLF33.36","SLF34.1","SLF34.2","SLF34.3","SLF34.4","SLF34.5","SLF34.6","SLF34.7","SLF34.8","SLF34.9","SLF34.10","SLF27.80","SLF27.81","SLF27.82","SLF27.83","SLF27.84","SLF27.79","SLF27.1","SLF27.2","SLF27.3","SLF27.4","SLF27.5","SLF27.6","SLF27.7","SLF27.8","SLF27.85","SLF27.86","SLF27.87","SLF27.88","SLF27.89","SLF27.90","SLF27.14","SLF27.15","SLF27.16","SLF27.17","SLF27.18","SLF27.19","SLF27.20","SLF27.21","SLF27.22","SLF27.23","SLF27.24","SLF27.25","SLF27.26","SLF27.27","SLF27.28","SLF27.29","SLF27.30","SLF27.31","SLF27.32","SLF27.33","SLF27.34","SLF27.35","SLF27.36","SLF27.37","SLF27.38","SLF27.39","SLF27.40","SLF27.41","SLF27.42","SLF27.43","SLF27.44","SLF27.45","SLF27.46","SLF27.47","SLF27.48","SLF27.49","SLF27.50","SLF27.51","SLF27.52","SLF27.53","SLF27.54","SLF27.55","SLF27.56","SLF27.57","SLF27.58","SLF27.59","SLF27.60","SLF27.61","SLF27.62","SLF27.63","SLF27.64","SLF27.65","SLF27.66","SLF27.67","SLF27.68","SLF27.69","SLF27.70","SLF27.71","SLF27.72","SLF27.73","SLF27.74","SLF27.75","SLF27.76","SLF27.77","SLF27.78","SLF27.9","SLF27.10","SLF27.11","SLF27.12","SLF27.13","SLF31.1","SLF31.2","SLF31.3","SLF31.4","SLF31.5","SLF31.6","SLF31.7","SLF31.8","SLF31.9","SLF31.10","SLF31.11","SLF31.12","SLF31.13","SLF31.14","SLF31.15","SLF31.16","SLF31.17","SLF31.18"]
    
    if set=="slf34":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale
		
        if len(channels) != 2:
            raise PyslidException("Two channels required for slf34")
        labels = [ 'protein', 'dna' ] 

        for c in xrange(2):
            img.channels[ labels[c] ] = channels[c]
            plane = pyslid.utilities.getPlane(
                conn, iid, pixels, channels[c], zslice, timepoint)
            img.channeldata[ labels[c] ] = scipy.misc.imresize(plane, scale)
        
        img.loaded=True
        features = []

        try:
            features = pyslic.computefeatures(img,'field-dna+')
            result = [feature_ids[0:173], features, scale]
        except:
            print "Unable to calculate features"
            raise
    elif set=="slf33":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale

        print 'scale: %f' % scale
        img.channels[ 'protein' ] = channels[0]
        plane = pyslid.utilities.getPlane(
            conn, iid, pixels, channels[0], zslice, timepoint)
        img.channeldata[ 'protein' ] = scipy.misc.imresize( plane, scale )

        img.loaded=True
        print 'img:%s shape:%s' % (img, img.channeldata['protein'].shape)
        ids = []
        features = []    

        indices=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163]
        for i in range(len(indices)):
            ids.append( feature_ids[indices[i]-1] )

        try:
            features = pyslic.computefeatures(img,'field+')
            result = [ids, features, scale]
        except:
            print "Unable to calculate features"
            raise
    elif set=="slf36":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale

        if len(channels) != 2:
           channels = [ 0, 1 ]
        labels = [ 'protein', 'dna' ] 

        for channel in channels:
            img.channels[ labels[channel] ] = channel
            plane = pyslid.utilities.getPlane(
                conn, iid, pixels, channel, zslice, timepoint)
            img.channeldata[ labels[channel] ] = scipy.misc.imresize( plane, scale )

        img.loaded=True
        ids = []
        features = []

        try:
            values = pyslic.computefeatures(img,'field-dna+')
            indices = [12,10,11,1,18,17,6,7,8,9,20,2,3,19,4,5,21,22,13,14,15,16]
            for i in range(len(indices)):
                ids.append( feature_ids[indices[i]-1] )
                values.append( values[indices[i]-1] )
            result = [ids, values, scale]
        except:
            print "Unable to calculate features" 
            raise
    elif set=="slf35":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale

        if len(channels) != 2:
            channels = [0, 1]
        labels = [ 'protein', 'dna' ] 

        for channel in channels:
            img.channels[ labels[channel] ] = channel
            img.channeldata[ labels[channel] ] = pyslid.utilities.getPlane(
                conn, iid, pixels, channel, zslice, timepoint)

        img.loaded=True
        ids = []
        features = []

        try:
            values = pyslic.computefeatures(img,'field-dna+')
            indices =[170,77,119,13,25,100,167,85,173,160,3,165,83,82,30,16,134,96,114,35,94,98,168]
            for i in range(len(indices)):
                ids.append( feature_ids[indices[i]-1] )
                features.append( values[indices[i]-1] )
            result = [ids, features, scale]
        except:
            print "Unable to calculate features"
            raise
    elif set=="min_max_mean":
        if len(channels) != 1:
            raise PyslidException("Expected 1 channel for featureset %s" % set)

        plane = pyslid.utilities.getPlane(
            conn, iid, pixels, channels[0], zslice, timepoint)
        ids = getIds(set)
        features = numpy.array([plane.min(), plane.max(), plane.mean()])
        result = [ids, features, scale]
    else:
        raise PyslidException("Invalid feature set name")

    # pyslic has a bug which can result in an incorrect number of features
    # being returned
    if len(result[0]) != len(result[1]):
        raise PyslidException(
            "Mismatch between featureids and feature values"
            "\nfids:%s\nfeatures:%s" % (result[0], result[1]))

    return result
Exemplo n.º 13
0
def calculate( conn, iid, scale=1, set="slf33", field=True, rid=None, pixels=0, channels=[], zslice=0, timepoint=0, threshold=None, debug=False ):
    '''
    Calculates and returns a feature ids and features vectors given a valid
    image identification (iid). It currently calculates SLF33, SLF34, SLF35 and SLF36.
    This method will try to retrieve the resolution of the image from the annotation. 

    If the method is unable to connect to the OMERO.server, then the method will return None.
    If the method doesn't find an image associated with the given image id (iid), then the
    method will return None.

    For detailed outputs, set debug flag to True.
    
    @param conn
    @param image id (iid)
    @param resolution (scale)
    @param slf set id (set)
    @param pixels
    @param timepoint
    @return [feature ids, feature values, scale]
    '''
   
    if not conn.isConnected():
        if debug:
            print "Unable to connect to OMERO.server"
        return [[],[],None]

    if not pyslid.utilities.hasImage( conn, iid ):
        if debug:
            print "No image found with the given image id"
        return [[],[],None]

    #check input arguments
    image = conn.getObject("Image", long(iid))

    if image is None:
        if debug:
            print "Unable to retrieve image"
        return [[],[],None]
    else:
        try:
            #if threshold is empty use default value
            if threshold == None:
                threshold = 10*1024;

            #check if image size is greater than threshold value
            #icaoberg 19/02/2013
            if image.getPixelSizeY() > threshold:
                if debug:
                    print "Image size is greater than threshold value"
                return [[],[],None]
            #icaoberg 19/02/2013
            elif image.getPixelSizeY() > threshold:
                if debug:
                    print "Image size is greater than threshold value"
                return [[],[],None]
            else:
                #set scale value
                imgScale = pyslid.image.getScale( conn, iid, debug )
                imgScale = imgScale[0]        
        except:
            #if no scale value is present, pyslic will set a scale value of .23
            #to avoid that we prevent feature calculation
            if debug:
                print "Unable to retrieve resolution of resolution was not set"
            return [[],[],None]

    #set resolution based on the scale
    if scale < 0.33 and abs(scale - imgScale)>0.001 :
         scale = imgScale
    elif scale < 0.67 and abs(scale - imgScale*2)>0.001:
         scale = imgScale*2
    else:
         scale = imgScale*4

    feature_ids = ["SLF27.66","SLF27.67","SLF27.68","SLF27.69","SLF27.70","SLF27.71","SLF27.72","SLF27.73","SLF27.74","SLF27.75","SLF27.76","SLF27.77","SLF27.78","SLF33.37","SLF33.38","SLF33.39","SLF33.40","SLF33.41","SLF33.42","SLF33.43","SLF33.44","SLF33.45","SLF33.46","SLF33.47","SLF33.48","SLF33.49","SLF33.50","SLF33.51","SLF33.52","SLF33.53","SLF33.54","SLF33.55","SLF33.56","SLF33.57","SLF33.58","SLF33.59","SLF33.60","SLF33.61","SLF33.62","SLF33.63","SLF33.64","SLF33.65","SLF33.66","SLF33.67","SLF33.68","SLF33.69","SLF33.70","SLF33.71","SLF33.72","SLF33.73","SLF33.74","SLF33.75","SLF33.76","SLF33.77","SLF33.78","SLF33.79","SLF33.80","SLF33.81","SLF33.82","SLF33.83","SLF33.84","SLF33.85","SLF33.86","SLF33.87","SLF33.88","SLF33.89","SLF33.90","SLF33.91","SLF33.92","SLF33.93","SLF33.94","SLF33.95","SLF33.96","SLF33.97","SLF33.98","SLF33.99","SLF33.100","SLF33.101","SLF33.102","SLF33.103","SLF33.104","SLF33.105","SLF33.106","SLF33.107","SLF33.108","SLF33.109","SLF33.110","SLF33.111","SLF33.112","SLF33.113","SLF33.114","SLF27.1","SLF27.2","SLF27.3","SLF27.4","SLF27.5","SLF27.89","SLF27.90","SLF27.9","SLF27.10","SLF27.11","SLF27.12","SLF27.13","SLF27.80","SLF27.81","SLF27.82","SLF27.83","SLF27.84","SLF27.79","SLF31.1","SLF31.2","SLF31.3","SLF31.4","SLF31.5","SLF31.6","SLF31.7","SLF31.8","SLF31.9","SLF31.10","SLF31.11","SLF31.12","SLF31.13","SLF31.14","SLF31.15","SLF31.16","SLF31.17","SLF31.18","SLF33.1","SLF33.2","SLF33.3","SLF33.4","SLF33.5","SLF33.6","SLF33.7","SLF33.8","SLF33.9","SLF33.19","SLF33.20","SLF33.21","SLF33.22","SLF33.23","SLF33.24","SLF33.25","SLF33.26","SLF33.27","SLF33.10","SLF33.11","SLF33.12","SLF33.13","SLF33.14","SLF33.15","SLF33.16","SLF33.17","SLF33.18","SLF33.28","SLF33.29","SLF33.30","SLF33.31","SLF33.32","SLF33.33","SLF33.34","SLF33.35","SLF33.36","SLF34.1","SLF34.2","SLF34.3","SLF34.4","SLF34.5","SLF34.6","SLF34.7","SLF34.8","SLF34.9","SLF34.10","SLF27.80","SLF27.81","SLF27.82","SLF27.83","SLF27.84","SLF27.79","SLF27.1","SLF27.2","SLF27.3","SLF27.4","SLF27.5","SLF27.6","SLF27.7","SLF27.8","SLF27.85","SLF27.86","SLF27.87","SLF27.88","SLF27.89","SLF27.90","SLF27.14","SLF27.15","SLF27.16","SLF27.17","SLF27.18","SLF27.19","SLF27.20","SLF27.21","SLF27.22","SLF27.23","SLF27.24","SLF27.25","SLF27.26","SLF27.27","SLF27.28","SLF27.29","SLF27.30","SLF27.31","SLF27.32","SLF27.33","SLF27.34","SLF27.35","SLF27.36","SLF27.37","SLF27.38","SLF27.39","SLF27.40","SLF27.41","SLF27.42","SLF27.43","SLF27.44","SLF27.45","SLF27.46","SLF27.47","SLF27.48","SLF27.49","SLF27.50","SLF27.51","SLF27.52","SLF27.53","SLF27.54","SLF27.55","SLF27.56","SLF27.57","SLF27.58","SLF27.59","SLF27.60","SLF27.61","SLF27.62","SLF27.63","SLF27.64","SLF27.65","SLF27.66","SLF27.67","SLF27.68","SLF27.69","SLF27.70","SLF27.71","SLF27.72","SLF27.73","SLF27.74","SLF27.75","SLF27.76","SLF27.77","SLF27.78","SLF27.9","SLF27.10","SLF27.11","SLF27.12","SLF27.13","SLF31.1","SLF31.2","SLF31.3","SLF31.4","SLF31.5","SLF31.6","SLF31.7","SLF31.8","SLF31.9","SLF31.10","SLF31.11","SLF31.12","SLF31.13","SLF31.14","SLF31.15","SLF31.16","SLF31.17","SLF31.18"]
    
    if set=="slf34":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale
		
        if len(channels) != 2:
            channels = [ 0, 1 ]
        labels = [ 'protein', 'dna' ] 

        for channel in channels:
            img.channels[ labels[channel] ] = channel
            plane = pyslid.utilities.getPlane(conn,iid,pixels,channel,zslice,timepoint)
            img.channeldata[ labels[channel] ] = scipy.misc.imresize(plane, scale)
        
        img.loaded=True
        features = []

        try:
             features = pyslic.computefeatures(img,'field-dna+')
             return [feature_ids[0:173], features, scale]
        except:
             if debug:
                 print "Unable to calculate features"
             return [[],[],None]
    elif set=="slf33":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale

        img.channels[ 'protein' ] = channels[0]
        plane = pyslid.utilities.getPlane(conn,iid,zslice,channels[0],timepoint)
        img.channeldata[ 'protein' ] = scipy.misc.imresize( plane, scale )

        img.loaded=True
        ids = []
        features = []    

        indices=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163]
        for i in range(len(indices)):
            ids.append( feature_ids[indices[i]-1] )

        try:
            features = pyslic.computefeatures(img,'field+')
            return [ids, features, scale]
        except:
            if debug:
                print "Unable to calculate features"
            return [[],[],None]
    elif set=="slf36":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale

        if len(channels) != 2:
           channels = [ 0, 1 ]
        labels = [ 'protein', 'dna' ] 

        for channel in channels:
            img.channels[ labels[channel] ] = channel
            plane = pyslid.utilities.getPlane(conn,iid,zslice,channel,timepoint)
            img.channeldata[ labels[channel] ] = scipy.misc.imresize( plane, scale )

        img.loaded=True
        ids = []
        features = []

        try:
            values = pyslic.computefeatures(img,'field-dna+')
            indices = [12,10,11,1,18,17,6,7,8,9,20,2,3,19,4,5,21,22,13,14,15,16]
            for i in range(len(indices)):
                ids.append( feature_ids[indices[i]-1] )
                values.append( values[indices[i]-1] )
            return [ids, values, scale]
        except:
            if debug:
               print "Unable to calculate features" 
            return [[],[],None]
    elif set=="slf35":
        #make pyslic image container
        img=pyslic.Image()
        img.label=iid
        img.scale=scale

        if len(channels) != 2:
            channels = [0, 1]
        labels = [ 'protein', 'dna' ] 

        for channel in channels:
            img.channels[ labels[channel] ] = channel
            img.channeldata[ labels[channel] ] = pyslid.utilities.getPlane(conn,iid,zslice,channel,timepoint)

        img.loaded=True
        ids = []
        features = []

        try:
            values = pyslic.computefeatures(img,'field-dna+')
            indices =[170,77,119,13,25,100,167,85,173,160,3,165,83,82,30,16,134,96,114,35,94,98,168]
            for i in range(len(indices)):
                ids.append( feature_ids[indices[i]-1] )
                features.append( values[indices[i]-1] )
            return [ids, features, scale]
        except:
            return [[],[], None]
    else:
        if debug:
           print "Invalid feature set name"
        ids = []
        features = []
        return [ids, features, None]
Exemplo n.º 14
0
def test_imgfeatcalc():
    Img=pyslic.Image()
    Img.channels['protein']=basedir+'/data/protimg.jp2'
    Img.channels['dna']=basedir+'/data/dnaimg.jp2'
    F=pyslic.computefeatures(Img,'SLF7dna')
    assert F.size == 90