예제 #1
0
    def load(self, fName, stackUnits=[1., 1., 1.]):
        if fName:
            fNames = glob.glob(os.path.join(fName, "*"))
            self.fNames = [f for f in fNames if re.match(".*\.(tif|tiff)", f)]

            if len(self.fNames) == 0:
                raise Exception("folder %s seems to be empty" % fName)
            else:
                self.fNames.sort()

            try:
                _tmp = imgutils.read3dTiff(self.fNames[0])
                _single_size = _tmp.shape
                if len(_single_size) == 2:
                    _single_size = (1, ) + _single_size

                if len(_single_size) != 3:
                    raise Exception("tiff stacks seem to be neither 2d nor 3d")

                self.stackSize = (len(self.fNames), ) + _single_size
            except Exception as e:
                print(e)
                self.fName = ""
                raise Exception("couldnt open %s as TiffData" % self.fNames[0])
                return

            self.stackUnits = stackUnits
            self.fName = fName
예제 #2
0
    def load(self, N=None):
        if N == None:
            logger.debug("loading precomputed demodata")
            self.data = imgutils.read3dTiff(
                absPath("../data/mpi_logo_80.tif")).astype(np.float32)
            N = 80
            self.stackSize = (10, N, N, N)
            self.fName = ""
            self.nT = 10
            self.stackUnits = (1, 1, 1)

        else:
            self.stackSize = (1, N, N, N)
            self.fName = ""
            self.nT = N
            self.stackUnits = (1, 1, 1)
            x = np.linspace(-1, 1, N)
            Z, Y, X = np.meshgrid(x, x, x, indexing="ij")
            R = np.sqrt(X**2 + Y**2 + Z**2)
            R2 = np.sqrt((X - .4)**2 + (Y + .2)**2 + Z**2)
            phi = np.arctan2(Z, Y)
            theta = np.arctan2(X, np.sqrt(Y**2 + Z**2))
            u = np.exp(-500 * (R - 1.)**2) * np.sum(
                np.exp(-150 * (
                    -theta - t + .1 *
                    (t - np.pi / 2.) * np.exp(-np.sin(2 *
                                                      (phi + np.pi / 2.))))**2)
                for t in np.linspace(-np.pi / 2., np.pi / 2., 10)) * (1 + Z)

            u2 = np.exp(-7 * R2**2)
            self.data = (10000 * (u + 2 * u2)).astype(np.float32)
예제 #3
0
    def load(self, N=None):
        if N == None:
            logger.debug("loading precomputed demodata")
            self.data = imgutils.read3dTiff(absPath("../data/mpi_logo_80.tif")).astype(np.float32)
            N = 80
            self.stackSize = (10, N, N, N)
            self.fName = ""
            self.nT = 10
            self.stackUnits = (1, 1, 1)

        else:
            self.stackSize = (1, N, N, N)
            self.fName = ""
            self.nT = N
            self.stackUnits = (1, 1, 1)
            x = np.linspace(-1, 1, N)
            Z, Y, X = np.meshgrid(x, x, x, indexing="ij")
            R = np.sqrt(X ** 2 + Y ** 2 + Z ** 2)
            R2 = np.sqrt((X - .4) ** 2 + (Y + .2) ** 2 + Z ** 2)
            phi = np.arctan2(Z, Y)
            theta = np.arctan2(X, np.sqrt(Y ** 2 + Z ** 2))
            u = np.exp(-500 * (R - 1.) ** 2) * np.sum(np.exp(-150 * (-theta - t + .1 * (t - np.pi / 2.) *
                                                                     np.exp(-np.sin(2 * (phi + np.pi / 2.)))) ** 2)
                                                      for t in np.linspace(-np.pi / 2., np.pi / 2., 10)) * (1 + Z)

            u2 = np.exp(-7 * R2 ** 2)
            self.data = (10000 * (u + 2 * u2)).astype(np.float32)
예제 #4
0
    def load(self, fName, stackUnits=[1., 1., 1.]):
        if fName:
            try:
                data = np.squeeze(imgutils.read3dTiff(fName))

                if not data.ndim in [2, 3, 4]:
                    raise ValueError(
                        "in file %s: dada.ndim = %s (not 2, 3 or 4)" %
                        (fName, data.ndim))

                if data.ndim == 2:
                    self.stackSize = (1, 1) + data.shape
                    data = data.copy().reshape(self.stackSize)

                elif data.ndim == 3:
                    self.stackSize = (1, ) + data.shape
                    data = data.copy().reshape(self.stackSize)
                else:
                    self.stackSize = data.shape

                self.data = data

            except Exception as e:
                print(e)
                self.fName = ""
                raise Exception("couldnt open %s as TiffData (%s)" %
                                (fName, str(e)))
                return

            self.stackUnits = stackUnits
            self.fName = fName
예제 #5
0
    def load(self, fName, stackUnits=[1., 1., 1.]):
        if fName:
            fNames = glob.glob(os.path.join(fName, "*"))
            self.fNames = [f for f in fNames if re.match(".*\.(tif|tiff)", f)]

            if len(self.fNames) == 0:
                raise Exception("folder %s seems to be empty" % fName)
            else:
                self.fNames.sort()

            try:
                _tmp = imgutils.read3dTiff(self.fNames[0])
                _single_size = _tmp.shape
                if len(_single_size) == 2:
                    _single_size = (1,) + _single_size

                if len(_single_size) != 3:
                    raise Exception("tiff stacks seem to be neither 2d nor 3d")

                self.stackSize = (len(self.fNames),) + _single_size
            except Exception as e:
                print(e)
                self.fName = ""
                raise Exception("couldnt open %s as TiffData" % self.fNames[0])
                return

            self.stackUnits = stackUnits
            self.fName = fName
예제 #6
0
    def load(self, fName, stackUnits=[1., 1., 1.]):
        if fName:
            try:
                data = np.squeeze(imgutils.read3dTiff(fName))

                if not data.ndim in [2, 3, 4]:
                    raise ValueError("in file %s: dada.ndim = %s (not 2, 3 or 4)" % (fName, data.ndim))

                if data.ndim == 2:
                    self.stackSize = (1, 1) + data.shape
                    data = data.copy().reshape(self.stackSize)

                elif data.ndim == 3:
                    self.stackSize = (1,) + data.shape
                    data = data.copy().reshape(self.stackSize)
                else:
                    self.stackSize = data.shape

                self.data = data

            except Exception as e:
                print(e)
                self.fName = ""
                raise Exception("couldnt open %s as TiffData (%s)" % (fName,str(e)))
                return

            self.stackUnits = stackUnits
            self.fName = fName
예제 #7
0
    def __getitem__(self, pos):
        if len(self.fNames) > 0 and pos < len(self.fNames):
            try:
                data = np.squeeze(imgutils.read3dTiff(self.fNames[pos]))
                data = data.reshape(self.stackSize[1:])
            except Exception as e:
                print(e)
                return None

            return data
예제 #8
0
    def __getitem__(self, pos):
        if len(self.fNames) > 0 and pos < len(self.fNames):
            try:
                data = np.squeeze(imgutils.read3dTiff(self.fNames[pos]))
                data = data.reshape(self.stackSize[1:])
            except Exception as e:
                print(e)
                return None

            return data
예제 #9
0
    def load(self, fNames, stackUnits=[1., 1., 1.]):
        if fNames:

            if len(self.fNames) == 0:
                raise Exception("filelist %s seems to be empty" % fNames)

            try:
                _tmp = imgutils.read3dTiff(self.fNames[0])
                _single_size = _tmp.shape
                if len(_single_size) == 2:
                    _single_size = (1, ) + _single_size

                if len(_single_size) != 3:
                    raise Exception("tiff stacks seem to be neither 2d nor 3d")

                self.stackSize = (len(self.fNames), ) + _single_size
            except Exception as e:
                print(e)
                raise Exception("couldnt open %s as TiffData" % self.fNames[0])
                return

            self.stackUnits = stackUnits
예제 #10
0
    def load(self, fNames, stackUnits=[1., 1., 1.]):
        if fNames:

            if len(self.fNames) == 0:
                raise Exception("filelist %s seems to be empty" % fNames)

            try:
                _tmp = imgutils.read3dTiff(self.fNames[0])
                _single_size = _tmp.shape
                if len(_single_size) == 2:
                    _single_size = (1,) + _single_size

                if len(_single_size) != 3:
                    raise Exception("tiff stacks seem to be neither 2d nor 3d")

                self.stackSize = (len(self.fNames),) + _single_size
            except Exception as e:
                print(e)
                raise Exception("couldnt open %s as TiffData" % self.fNames[0])
                return

            self.stackUnits = stackUnits
예제 #11
0
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
        description="""renders max projectios of 3d data

    example usage:

    Tif data: \t \tspim_render  -i mydata.tif -o myoutput.png -t 0 0 -4 -u 1 1 4
    Bscope data:  \tspim_render -f bscope -i mydataFolder -o myoutput.png -t 0 0 -4 -u 1 1 4
    """)

    parser.add_argument("-f","--format",dest="format",metavar="format",
                        help = """format currently supported:
    tif (default)
    bscope  """,
                        type=str,default = "tif", required = False)

    parser.add_argument("-i","--input",dest="input",metavar="infile",
                        help = "name of the input file to render, currently only 3d Tiff is supported",
                        type=str,default = None, required = True)

    parser.add_argument("-o","--output",dest="output",metavar="outfile",
                        help = "name of the output file,  png extension is recommended",
                        type=str,default = "out.png")

    parser.add_argument("-p","--pos",dest="pos",metavar="timepoint position",
                        help = "timepoint to render if format=='bscope' ",
                        type=int,default = 0)

    parser.add_argument("-w","--width",dest="width",metavar="width",
                        help = "pixelwidth of the rendered output ",
                        type=int,default = 400)

    parser.add_argument("-s","--scale",dest="scale",metavar="scale",
                        type=float,nargs=1 ,default = [1.])


    parser.add_argument("-u","--units",dest="units",metavar="units",
                        type=float,nargs= 3 ,default = [1.,1.,5.])


    parser.add_argument("-t","--translate",dest="translate",
                        type = float, nargs=3,default = [0,0,-4],
                        metavar=("x","y","z"))

    parser.add_argument("-r","--rotation",dest="rotation", type =
                        float, nargs=4,default = [0,1,0,0],
                        metavar=("w","x","y","z"))

    parser.add_argument("-R","--range",dest="range", type =
                        float, nargs=2,default = None,
                        help = "if --16bit is set, the range of the data values to consider, defaults to [min,max]",
                        metavar=("min","max"))


    parser.add_argument("-O","--Orthoview",help="use parallel projection (default: perspective)",
                        dest="ortho",action="store_true")

    parser.add_argument("--16bit",help="render into 16 bit png",
                        dest="is16Bit",action="store_true")

    if len(sys.argv)==1:
        parser.print_help()
        return

    args = parser.parse_args()


    for k,v in six.iteritems(vars(args)):
        print(k,v)

    rend = VolumeRenderer((args.width,args.width))

    if args.format=="tif":
        data = read3dTiff(args.input)
    elif args.format=="bscope":
        data = fromSpimFolder(args.input,pos=args.pos,count=1)[0,...]
    else:
        raise ValueError("format %s not supported (should be tif/bscope)" %args.format)

    rend.set_data(data)
    rend.set_units(args.units)

    M = mat4_scale(*(args.scale*3))
    M = np.dot(mat4_rotation(*args.rotation),M)
    M = np.dot(mat4_translate(*args.translate),M)

    rend.set_modelView(M)

    if args.ortho:
        rend.set_projection(mat4_ortho(-1,1,-1,1,-1,1))
    else:
        rend.set_projection(mat4_perspective(60,1.,1,10))

    out = rend.render()

    # image is saved by scipy.misc.toimage(out,low,high,cmin,cmax)
    # p' = p * high/cmax

    if not args.is16Bit:
        imsave(args.output,out)
        # if not args.range:
        #     imsave(args.output,out)
        # else:
        #     img = toimage(out, low = args.range[0], high  = args.range[1])
        #     img.save(args.output)

    else:
        if not args.range:
            print("min/max: ", np.amin(out), np.amax(out))
            img = toimage(out, low = np.amin(out), high  = np.amax(out),mode = "I")
        else:
            img = toimage(out, low = args.range[0], high  = args.range[1], mode = "I")
        img.save(args.output)