Example #1
0
def main():
    try:
        stackdir = sys.argv[1]
    except IndexError:
        print "Usage: %s stack_dir [output_dir] [sdx] [sdy] [sdz]" % os.path.basename(sys.argv[0])
        sys.exit(1)

    ifiles = stackhandle.get_stack_files(stackdir)

    try:
        output_dir = sys.argv[2]
    except IndexError:
        output_dir = 'output/'
        print "Using default output directory output/"

    print "Called with", stackdir, output_dir

    try:
        sdx, sdy, sdz = int(sys.argv[3]), int(sys.argv[4]), int(sys.argv[5])
    except IndexError:
        print "Using default values for standard deviation"
        sdx, sdy, sdz = 8, 8, 6

    sds = 5

    print "Using standard deviations: %d, %d, %d" % (sdx, sdy, sdz)

    ma = load_png_stack(ifiles)

    flush_message("Applying 3D gaussian filter...")
    bl = nd.gaussian_filter(ma, [sdx, sdy, sdz])
    print "done"

    flush_message("Finding projection surface...")
    ps = proj.max_indices_z(bl)
    print "done"

    sps = nd.gaussian_filter(ps, sds)
    _, _, zmax = ma.shape
    vis_factor = 255 / zmax
    sfilename = os.path.join(output_dir, "surface-g3d-%d-%d-%d-%d.png" % (sdx, sdy, sdz, sds))
    scipy.misc.imsave(sfilename, sps * vis_factor)

    flush_message("Generating projection from surface...")
    res = proj.projection_from_surface_z(ma, sps, dm=3, dp=0) 
    print "done"

    filename = os.path.join(output_dir, "proj-g3d-%d-%d-%d-%d.png" % (sdx, sdy, sdz, sds))
    pmax = np.amax(res)
    vis_scale = 255 / pmax
    scipy.misc.imsave(filename, res * vis_scale)

    flush_message("Post processing...")
    pp = projpp.proj_filter(res * vis_scale, 3, 60, 15)
    print "done"

    filename = os.path.join(output_dir, 'proj-pp-%d-%d-%d-%d.png' % (sdx, sdy, sdz, sds))
    scipy.misc.imsave(filename, pp)
def main(args):
	javabridge.start_vm(class_path=bf.JARS)
	
	try:
		lifdir = sys.argv[1]
	except IndexError:
		print "Usage: %s lif_directory [sdx] [sdy] [sdz]" % os.path.basename(sys.argv[0])
		sys.exit(1)
		
	try:
            sdx, sdy, sdz = int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4])
        except IndexError:
            print "Using default values for standard deviation"
            sdx, sdy, sdz = 4, 4, 3
		
	md = bf.get_omexml_metadata(lifdir)
	mdo = bf.OMEXML(md)	
	rdr = bf.ImageReader(lifdir, perform_init=True)
	
	
	names, sizes, resolutions = parse_xml_metadata(md)
	
	
	print '%s contains:' % lifdir
	for i in range(mdo.image_count):
		print '%d, %s, %s' % (i,names[i],(sizes[i],))
	
	
	
	for im_num in range(mdo.image_count):
		im_size = ()
		im_size = [sizes[im_num][1],sizes[im_num][2],sizes[im_num][0],3]
	
		image3d = np.empty(im_size, np.uint8)
		print 'projecting: %d, %s, %s' % (im_num,names[im_num],(sizes[im_num],))
		
		z_size = sizes[im_num][0]
		
		flush_message('Importing...')
		for z in range(z_size):
			image3d[:,:,z,:] = rdr.read(z=z, series=im_num, rescale=False)
		print 'done'

		#ma = greyScale(image3d)
		ma = np.amax(image3d, 3)
		
		#sdx, sdy, sdz = 4, 4, 3
		sds = 4
	
		output_dir = "./proj_%s_%s" % (lifdir, im_num)
	
		if not os.path.exists(output_dir):
			os.makedirs(output_dir)
		
		max_proj = np.amax(ma, axis=2)
		
		mpfilename = os.path.join(output_dir, "max-proj.png")
		scipy.misc.imsave(mpfilename, max_proj)
		
		bl = nd.gaussian_filter(ma, [sdx, sdy, sdz])

		#ps = find_projection_surface(bl)
		ps = proj.max_indices_z(bl)

		sps = nd.gaussian_filter(ps, sds)
		
		vis_factor = 255 / z_size
		sfilename = os.path.join(output_dir, "surface-g3d-%d-%d-%d-%d.png" % (sdx, sdy, sdz, sds))
		scipy.misc.imsave(sfilename, sps * vis_factor)

		res = proj.projection_from_surface(ma, sps, dm=3, dp=0)

		filename = os.path.join(output_dir, "proj-g3d-%d-%d-%d-%d.png" % (sdx, sdy, sdz, sds))
		pmax = np.amax(res)

		vis_scale = 255 / pmax

		scipy.misc.imsave(filename, res * vis_scale)

		flush_message("Post processing...")
		pp = projpp.proj_filter(res * vis_scale, 3, 60, 15)
		print " done"
		filename = os.path.join(output_dir, 'proj-pp-%d-%d-%d-%d.png' % (sdx, sdy, sdz, sds))
		scipy.misc.imsave(filename, pp)
	
	javabridge.kill_vm()
	return 0