Ejemplo n.º 1
0
def SaveShowImage(Matrix, Root=None, Suffix=None):
    '''Save Image if Root is valid, otherwise show it on the screen.'''
    Name = MATL.MakeRoot(Root=Root, Suffix=Suffix)
    if Name is not None:
        SaveImage(Matrix, Name)
    else:
        ShowImage(Matrix)
Ejemplo n.º 2
0
def ScanPoints(InputFolder,ImageExtension,ImagePrefix=None,PointsList=[(0,0)]):
    Limg = MATL.getFiles(InputFolder,ImageExtension,ImagePrefix)
    Lxml = MATL.getFiles(InputFolder,"xml",ImagePrefix)

    #Get Angles
    A=[]
    for xmlf in Lxml:
        A.append(GetXMLAngle(xmlf))
    A.append(-180)

    #Get Inensities
    I=[]
    for imgf in Limg:
        I.append([])
        for pos in PointsList:
            I[-1].append(GetIntesity(imgf,pos))
    I.append(I[0])           
    I=[list(i) for i in zip(*I)]
    return A,I,Limg[0]
Ejemplo n.º 3
0
    def runstreamline(Input1, Input2, Output):
        thismodule = os.path.abspath(inspect.getfile(inspect.currentframe()))
        quotInput1 = '"' + Input1 + '"'
        quotInput2 = '"' + Input2 + '"'
        quotOutput = '"' + Output + '"'

        cmd = " ".join([
            "py -2", thismodule, quotInput1, quotInput2, quotOutput,
            "-Offset1 70"
        ])
        MATL.RunProgram(cmd)
Ejemplo n.º 4
0
def SaveTif(Matrix, Name, resolution=None):
    '''Save pixel data in matrix as 32-bit float on a tif file.'''
    Name = MATL.FixName(Name, '.tif')
    MyImage = Image.fromarray(np.float32(Matrix), mode="F")
    if resolution:
        xres, yres = resolution
        kwargsdict = {
            282: xres,
            283: yres,
            270: 'ImageJ=1.51w\nunit=micron\n',
            296: 1
        }
        MyImage.save(Name, tiffinfo=kwargsdict)
    else:
        MyImage.save(Name)
Ejemplo n.º 5
0
def Make3DSurfaceFromHeightMapTiff(File, OFile=None, NoZeros=False):
    ''' Generates a ply mesh from a tiff file. Scale is extracted from tiff embedded information.
    
    File - Tiff file with the height information
    OFile[None] - Path to output ply file
    NoZeros[False] - Do not generate mesh when pixel/element value is equal to zero.
    '''
    name, _ = os.path.splitext(File)
    if OFile is None:
        outfile = name + "_out.ply"
    else:
        outfile = MATL.FixName(OFile, "ply")

    Mpix, res = MAIP.GetImageMatrix(File, Silent=True, GetTiffRes=True)

    return MakeMPixMesh(Mpix,
                        Scale=(1 / res[0], 1 / res[1], 1.0),
                        Expfile=outfile,
                        NoZeros=NoZeros)
Ejemplo n.º 6
0
 def test_macauley(self):
     self.assertTrue(np.all(MATL.macauley(np.array([3,-3]),True)==np.array([3,0])))
     self.assertTrue(np.all(MATL.macauley(np.array([3,-3]),False)==np.array([0,-3])))
Ejemplo n.º 7
0
 def test_getMatfromCSV(self):
     csvdata="1,2  ,3\n4 , 5,6\n    7,8,9"
     csvfile=os.path.join(self.temppath,"mycsvfile.csv")
     with open(csvfile,'w') as f:
         f.write(csvdata)
     self.assertTrue(np.all(MATL.getMatfromCSV(csvfile)==[[1,2,3],[4,5,6],[7,8,9]]))
Ejemplo n.º 8
0
 def test_Timeme(self):
     avgtime=MATL.Timeme(max,[4,5,6],NN=2,NNN=2,show=False)
     self.assertTrue(avgtime>=0)
Ejemplo n.º 9
0
 def test_TicToc(self):
     start=MATL.Tic()
     delta=MATL.Toc(start)
     self.assertTrue(delta>=0)
Ejemplo n.º 10
0
 def test_IsNew(self):
     myfile_new = MATL.MakeRoot(self.temppath,"new")
     open(myfile_new,'w+').close()
     self.assertFalse(MATL.IsNew(self.myfile_old,myfile_new))
     self.assertTrue(MATL.IsNew(myfile_new,self.myfile_old))
Ejemplo n.º 11
0
 def test_getFiles(self):
     FileNameList=['firsttest','secondtest','thirdtest']
     for fn in FileNameList:
         fileloc = os.path.join(self.temppath,fn+".myext")
         open(fileloc,'w+').close()
     self.assertTrue([os.path.splitext(os.path.basename(x))[0] for x in MATL.getFiles(self.temppath,"myext")]==FileNameList)
Ejemplo n.º 12
0
def SaveImageRGB(Matrix, Name, **kwargs):
    '''Save pixel data in matrix as RGB on a file.'''
    Name = MATL.FixName(Name, '.png')
    if not type(Matrix[0, 0]) == np.ndarray:
        Matrix = ConvertToRGB(Matrix, **kwargs)
    Image.fromarray(Matrix, mode="RGBA").save(Name, "png")
Ejemplo n.º 13
0
 def setUpClass(cls):
     print("\n === test_MA_Tools === ")
     cls.temppath = os.path.join("test","temp","")
     #MATL.MakeNewDir(cls.temppath)
     cls.myfile_old = MATL.MakeRoot(cls.temppath,"old")
     open(cls.myfile_old,'w+').close()
Ejemplo n.º 14
0
def SaveImageRaw(Matrix, Name, TifRes=None, resolution=None):
    '''Save pixel data in matrix as 32-bit float on a file.'''
    Name = MATL.FixName(Name, '.tif')
    Image.fromarray(np.float32(Matrix), mode="F").save(Name,
                                                       "TIFF",
                                                       dpi=resolution)
Ejemplo n.º 15
0
def MakeCSVMesh(CSVfile, verbose=True, **kwargs):
    ''' Generates a ply mesh from a csv file '''
    if verbose: print("*Making CSV Mesh")
    if verbose: print("  - Reading .csv")
    npdata = MATL.getMatfromCSV(CSVfile)
    return MakeMPixMesh(npdata, verbose, **kwargs)
Ejemplo n.º 16
0
    # tiffile_unscaled = os.path.join(BaseFolder,'0kPa.tif')
    # tiffile = os.path.join(BaseFolder,'0kPa_scaled.tif')
    tiffile = os.path.join(BaseFolder, '0kPa.tif')
    plyFile_Orig = os.path.join(BaseFolder, '0kPa_scaled.ply')
    plyFile_Smooth = os.path.join(BaseFolder, '0kPa_scaled_smooth.ply')
    matlabdata = r'C:\Users\Wenbin\Desktop\FIDVC-master\Matlab Code\dm2\resultsFIDVC.mat'
    vtuout = os.path.join(BaseFolder, '0kPa_scaled_smooth.vtu')

    # Scale Tif height map to fix spherical distorsion
    #    if Force or MATL.IsNew(tiffile_unscaled,tiffile):
    #        print("Scaling Tif file...")
    #        scalefactor = 1.335 #(nPBS/nH20)
    #        MAIP.ScaleTif(tiffile_unscaled,tiffile,scalefactor)

    # Make ply from height map if heightmap is newer
    if Force or MATL.IsNew(tiffile, plyFile_Orig):
        print("Making 3D Surface...")
        MA3D.Make3DSurfaceFromHeightMapTiff(tiffile,
                                            OFile=plyFile_Orig,
                                            NoZeros=True)

    # Smooth ply file if input ply is new
    if True or MATL.IsNew(plyFile_Orig, plyFile_Smooth):
        print("Smoothing and reducing Surface...")
        MACA.SmoothPly(plyFile_Orig,
                       plyFile_Smooth,
                       ScriptFileName=None,
                       Verbose=True,
                       MeshLabPath='C:\\Program Files\\VCG\\MeshLab')

    test = AddDeformation(plyFile_Smooth)
Ejemplo n.º 17
0
                "shellBC": True
            },
            "ME_Average": {
                **casedefault, "kip": 0.184,
                "load": -2E-2,
                "shellBC": True
            },
            "ME_Uniform": {
                **casedefault, "kip": 0.5,
                "load": -2E-2,
                "shellBC": True
            },
        }

        destfolder = pjoin(Base_Folder, root)
        MATL.MakeNewDir(destfolder)

        for case in Cases:
            print(root + " " + case)
            casefolder = pjoin(destfolder, case)
            MATL.MakeNewDir(casefolder)
            febiofile = pjoin(casefolder, root + "_" + case + ".feb")

            if RunModels:
                FEBio.SaveFile(febiofile, **Cases[case])
                print("    Running FEBio. Check logfile for details...")
                MATL.RunProgram('FEBio2 "' + febiofile + '"', f_print=False)
                print("    FEBio Simulation finished.")

            logfile = os.path.splitext(febiofile)[0] + ".log"
            with open(logfile, "r") as fp:
Ejemplo n.º 18
0
def SaveImage(Matrix, Name, resc=False):
    '''Save pixel data in matrix as 8-bit on a file.'''
    Name = MATL.FixName(Name, '.png')
    if resc:
        Matrix = Rescale8bit(Matrix)
    Image.fromarray(np.uint8(Matrix), mode="L").save(Name, "png")
Ejemplo n.º 19
0
 def test_RunProgram(self):
     MATL.RunProgram("python -c \"print(0)\"",False)
Ejemplo n.º 20
0
 def test_eig33s(self):
     mat=np.array([[1,7,6],[7,2,5],[6,5,3]])
     normdiff=np.linalg.norm(
         np.sort(list(MATL.eig33s(mat[0,0],mat[1,1],mat[2,2],mat[0,1],mat[0,2],mat[1,2])))-
         np.sort(np.linalg.eigvals(mat)))
     self.assertTrue(normdiff<1E-12)
Ejemplo n.º 21
0
 def test_MakeRoot(self):
     mynewfile = MATL.MakeRoot(self.temppath,"TEST")
     open(mynewfile,'w+').close()
     self.assertTrue(os.path.isfile(os.path.join(self.temppath,"TEST")))