Exemplo n.º 1
0
    def __init__(self, fn):
        arr = Mrc.bindFile(fn)
        self.pxlsiz = arr.Mrc.hdr.d
        self.waves = arr.Mrc.hdr.wave[:arr.Mrc.hdr.NumWaves].copy()
        self.refwave = self.waves[arr.Mrc.hdr.n1]
        self.XYsize = arr.Mrc.hdr.Num[:2]
        self.nt = arr.Mrc.hdr.NumTimes
        self.nw = len(self.waves)
        self.t = 0
        self.dtype = arr.dtype.type
        if 'SIR' in fn:
            self.mid = 512
        else:
            self.mid = 256

        if arr.Mrc.hdr.n2 == 1:
            parm = arr
            nentry = aligner.NUM_ENTRY
            self.map_str = 'None'
        else:
            parm = arr.Mrc.extFloats[:arr.Mrc.hdr.NumTimes *
                                     arr.Mrc.hdr.NumWaves, :arr.Mrc.hdr.
                                     NumFloats]
            nentry = arr.Mrc.hdr.NumFloats
            self.nz = arr.Mrc.hdr.Num[-1] / (arr.Mrc.hdr.NumTimes *
                                             arr.Mrc.hdr.NumWaves * 2)
            if self.nz == 1:
                self.map_str = 'Projection'
            else:
                self.map_str = 'Section-wise'
        parm = parm.reshape(
            (arr.Mrc.hdr.NumTimes, arr.Mrc.hdr.NumWaves, nentry))
        self.alignParms = parm.copy()  # writable

        del arr, parm
Exemplo n.º 2
0
def makeFiles(fns, std=10, div_step=50, div_max=800):  #1000):
    """
    makes a series of images added Gaussain and Poisson noise

    std: standard deviation for Gaussian, and mean=std*10 for Poisson
    div_step: the step that the original image is divided while noise is added
    div_max: the maximum value that the original image is divided

    return output filenames
    """

    outs = []

    for fn in fns:
        a = Mrc.bindFile(fn)

        for ns in NOISE_STATS:
            hdr = mrcIO.makeHdr_like(a.Mrc.hdr)

            if ns == NOISE_STATS[0]:
                noise = F.noiseArr(a.shape, stddev=std, mean=0)
            else:
                noise = F.poissonArr(a.shape, mean=std * 10)
            steps = range(div_step, div_max + div_step, div_step)
            ag = [a / c + noise for c in steps]
            for i, arr in enumerate(ag):
                val = steps[i]
                if hasattr(arr, "Mrc"):
                    del arr.Mrc
                if arr.dtype == N.float64:
                    arr = arr.astype(N.float32)
                    hdr.PixelType = 2

                out = a.Mrc.path + ns + '%04d' % val
                Mrc.save(arr, out, ifExists='overwrite', hdr=hdr)
                outs.append(out)
    return outs