Пример #1
0
print 'Opening: ' + fname
image = imgutil.loadimg(fname, from_database=True)

tic = time.clock()
# Clean-up the image:
#image = flatfield.NormalizeColumnGains(image,Plot=0,Wiener=0)
image = flatfield.ImgNormalize(image, Method="mean")
toc = time.clock()

# Find star centroids:
centroids = []
(centers) = centroid.findstars(image,
                               zreject=3,
                               zthresh=3.0,
                               zpeakthresh=4,
                               min_pix_per_star=6,
                               max_pix_per_star=60,
                               oblongness=2,
                               debug=True)
centroids = centroid.imgcentroid(image, centers)

# Display image with stars circled:
vf = 3
if centroids:
    imgutil.circstars(image, centroids, 20, viewfactor=vf)
else:
    print 'Oopsies... we found ZERO centroids. Now how do you feel?'
    imgutil.dispimg(image, viewfactor=vf)

print 'Total time: ', toc - tic, ' s'
#DRCMoutfile = '../testimgdir/DRCMsubdimg.tif'   # dark row column average subtraction
#CMoutfile = '../testimgdir/CM10xsubdimg.tif'       # column average subtraction
#CSMoutfile = '../testimgdir/CM10xsubdimg.tif'       # column sigma range average subtraction

# load
print 'loading image...'
img = imgutil.loadimg(datpic)
#fullimg = imgutil.loadimg(datpic,'full')

# do subtractions
print 'doing subtraction...'
#DRCMimg = submethods.darkcolsub(fullimg)
#CMimg = submethods.colmeansub(img)
#CSMimg = submethods.colsigsub(img)
ix,iy = 1080,1080-10
iw,ih = 4,5
window,(x,y),(cx,cy) = submethods.windowsub(img,(ix,iy),(iw,ih))


# display images
#imgutil.dispimg(DRCMimg)
print 'displaying image...'
#imgutil.dispimg(CMimg,10) # displayed with an optional view factor of 10
imgutil.dispimg(window)
#imgutil.dispimg(img[100:100+int(5*2.5)+1][:,100:100+int(4*2.5)+1])

# save images
#imgutil.saveimg(DRCMimg,DRCMoutfile)
#imgutil.saveimg(CMimg,CMoutfile,10) # saved with an optional view factor of 10

import script_setup
from util import imgutil as imgutil
# from util import *

# image in paths
tifpicIN = '../testimgdir/img_1348355543_717188_00015_00000_0_gray.tif'
datpicIN = '../testimgdir/img_1348355543_717188_00015_00000_0.dat'
#image out path
tifpicOUT = '../testimgdir/tifpicsaved.tif'
datpicOUT = '../testimgdir/datpicsaved.tif'

loadedtif = imgutil.loadimg(tifpicIN)
loadeddat = imgutil.loadimg(datpicIN)

# display loaded dat
imgutil.dispimg(loadedtif)
imgutil.dispimg(loadeddat)

# try out new centroids display
#cents = [(0,0),(100.0,100.0),(500.5,500.5),(700,1700),(1200,1200),(1500.5,1500.5),(2000,2000)]
#loadeddat[700][1700] = 60000
#imgutil.circstars(loadeddat,cents)


# test new load with optional cropping
#fulldat = imgutil.loadimg(datpicIN,'full')
#imgutil.dispimg(fulldat)

# save loaded pictures
#imgutil.saveimg(loadedtif,tifpicOUT)
#imgutil.saveimg(loadeddat,datpicOUT)
# image path setup
datpic = '../testimgdir/img_1348355543_717188_00015_00000_0.dat'
#DRCMoutfile = '../testimgdir/DRCMsubdimg.tif'   # dark row column average subtraction
#CMoutfile = '../testimgdir/CM10xsubdimg.tif'       # column average subtraction
#CSMoutfile = '../testimgdir/CM10xsubdimg.tif'       # column sigma range average subtraction

# load
print 'loading image...'
img = imgutil.loadimg(datpic)
#fullimg = imgutil.loadimg(datpic,'full')

# do subtractions
print 'doing subtraction...'
#DRCMimg = submethods.darkcolsub(fullimg)
#CMimg = submethods.colmeansub(img)
#CSMimg = submethods.colsigsub(img)
ix, iy = 1080, 1080 - 10
iw, ih = 4, 5
window, (x, y), (cx, cy) = submethods.windowsub(img, (ix, iy), (iw, ih))

# display images
#imgutil.dispimg(DRCMimg)
print 'displaying image...'
#imgutil.dispimg(CMimg,10) # displayed with an optional view factor of 10
imgutil.dispimg(window)
#imgutil.dispimg(img[100:100+int(5*2.5)+1][:,100:100+int(4*2.5)+1])

# save images
#imgutil.saveimg(DRCMimg,DRCMoutfile)
#imgutil.saveimg(CMimg,CMoutfile,10) # saved with an optional view factor of 10
###################################################################################
# Load the image:
db = database.Connect()
fnames = db.select('select raw_fn from rawdata where burst_num = 185 limit 2').raw_fn.tolist()
fnames.sort()
fname = fnames[0]
print 'Opening: ' + fname
image = imgutil.loadimg(fname,from_database=True)

tic = time.clock()
# Clean-up the image:
#image = flatfield.NormalizeColumnGains(image,Plot=0,Wiener=0)
image = flatfield.ImgNormalize(image, Method="mean")
toc = time.clock()

# Find star centroids:
centroids = []
(centers) = centroid.findstars(image,zreject=3, zthresh=3.0, zpeakthresh=4, min_pix_per_star=6, max_pix_per_star=60, oblongness=2,debug=True)
centroids = centroid.imgcentroid(image,centers)

        
# Display image with stars circled:
vf = 3
if centroids:
    imgutil.circstars(image,centroids,20,viewfactor=vf)
else:
    print 'Oopsies... we found ZERO centroids. Now how do you feel?'
    imgutil.dispimg(image,viewfactor=vf)

print 'Total time: ',toc - tic,' s'
Пример #6
0
import script_setup
from util import imgutil as imgutil
# from util import *

# image in paths
tifpicIN = '../testimgdir/img_1348355543_717188_00015_00000_0_gray.tif'
datpicIN = '../testimgdir/img_1348355543_717188_00015_00000_0.dat'
#image out path
tifpicOUT = '../testimgdir/tifpicsaved.tif'
datpicOUT = '../testimgdir/datpicsaved.tif'

loadedtif = imgutil.loadimg(tifpicIN)
loadeddat = imgutil.loadimg(datpicIN)

# display loaded dat
imgutil.dispimg(loadedtif)
imgutil.dispimg(loadeddat)

# try out new centroids display
#cents = [(0,0),(100.0,100.0),(500.5,500.5),(700,1700),(1200,1200),(1500.5,1500.5),(2000,2000)]
#loadeddat[700][1700] = 60000
#imgutil.circstars(loadeddat,cents)

# test new load with optional cropping
#fulldat = imgutil.loadimg(datpicIN,'full')
#imgutil.dispimg(fulldat)

# save loaded pictures
#imgutil.saveimg(loadedtif,tifpicOUT)
#imgutil.saveimg(loadeddat,datpicOUT)
Пример #7
0
def main():
    '''
    Use this to test the procedural differences in image normalization"
    '''
    
    # Method
    Method = "mean"
    
    # Load image
#    fn = "/Users/zachdischner/Desktop/StarTest_9_9_2012/Gray/img_1347267746_089087_00006_00017_0_gray.tif"
#    fn = "/Users/zachdischner/Desktop/img_1353551010_808501_00000_00039_1.dat"
    fn = "/Users/zachdischner/Desktop/img.dat"
    img=imgutil.loadimg(fn,load_full=1)

    # Print means and standard deviations
    print "Using " + Method + " Method for normalization"
    print ""
    print "Original image mean and standard deviation:  %s    and    %s  " % (np.mean(img),np.std(img))

    i2 = NormalizeColumnGains(img,Plot=1,JustDark=1,Method=Method)
    pylab.title('Just Dark Row Normalization Using ' + Method )
    print "Just using Dark rows, image size is: "
    print i2.shape
    print "Dark Row based image mean and standard deviation:  %s    and    %s  " % (np.mean(i2),np.std(i2))


    i3 = NormalizeColumnGains(img,Plot=1,Method=Method)
    pylab.title('Using Dark row and Whole Image Using ' + Method )

    print "Now using the entire image, image size is: "
    print i3.shape
    print "DR + Image Column mean and standard deviation:  %s    and    %s  " % (np.mean(i3),np.std(i3))

    print "Adding a Wiener Filter"
    iwiener=NormalizeColumnGains(img,Plot=1,Method=Method,Wiener=1)
    print "DR + Image Column  + Wiener mean and standard deviation:  %s    and    %s  " % (np.mean(iwiener),np.std(iwiener))

    # Plotting
    pylab.figure(num=None, figsize=(13, 7), dpi=80, facecolor='w', edgecolor='k')
    pylab.subplot(2,2,1)
    pylab.imshow(np.multiply(img,4), cmap=None, norm=None, aspect=None, interpolation='nearest', vmin=0, vmax=2048, origin='upper')
    pylab.title('Original Image')

    pylab.subplot(2,2,2)
    pylab.imshow(np.multiply(i2,4), cmap=None, norm=None, aspect=None, interpolation='nearest', vmin=0, vmax=2048, origin='upper')
    pylab.title("Dark Row normalization Using " + Method )

    pylab.subplot(2,2,3)
    pylab.imshow(np.multiply(i3,4), cmap=None, norm=None, aspect=None, interpolation='nearest', vmin=0, vmax=2048, origin='upper')
    pylab.title('DR and Img Col Using ' + Method)

    pylab.subplot(2,2,4)
#    pylab.imshow(np.multiply(iwiener,4), cmap=None, norm=None, aspect=None, interpolation='nearest', vmin=0, vmax=2048, origin='upper')
#    pylab.title('Adding Wiener Filter to ' + Method)
#    oldmean=centroid.frobomad(img, axis=0)[0]
#    newmean=centroid.frobomad(i3, axis=0)[0]
    oldmean=np.mean(img,axis=0)
    newmean=np.mean(i3,axis=0)
    pylab.plot(oldmean)

    pylab.plot(newmean)
    pylab.legend(['Before Normalization Col RMean','After Normalization Col RMean'])
    pylab.xlabel('Column')
    pylab.ylabel('Mean')

    imgutil.dispimg(i3,viewfactor=4.)
    pylab.title('DR + IMGnorm')
    imgutil.dispimg(iwiener,viewfactor=4.)
    pylab.title('DR + IMGnorm + Wiener')

    return i3
Пример #8
0
def main():
    '''
    Use this to test the procedural differences in image normalization"
    '''

    # Method
    Method = "mean"

    # Load image
    #    fn = "/Users/zachdischner/Desktop/StarTest_9_9_2012/Gray/img_1347267746_089087_00006_00017_0_gray.tif"
    #    fn = "/Users/zachdischner/Desktop/img_1353551010_808501_00000_00039_1.dat"
    fn = "/Users/zachdischner/Desktop/img.dat"
    img = imgutil.loadimg(fn, load_full=1)

    # Print means and standard deviations
    print "Using " + Method + " Method for normalization"
    print ""
    print "Original image mean and standard deviation:  %s    and    %s  " % (
        np.mean(img), np.std(img))

    i2 = NormalizeColumnGains(img, Plot=1, JustDark=1, Method=Method)
    pylab.title('Just Dark Row Normalization Using ' + Method)
    print "Just using Dark rows, image size is: "
    print i2.shape
    print "Dark Row based image mean and standard deviation:  %s    and    %s  " % (
        np.mean(i2), np.std(i2))

    i3 = NormalizeColumnGains(img, Plot=1, Method=Method)
    pylab.title('Using Dark row and Whole Image Using ' + Method)

    print "Now using the entire image, image size is: "
    print i3.shape
    print "DR + Image Column mean and standard deviation:  %s    and    %s  " % (
        np.mean(i3), np.std(i3))

    print "Adding a Wiener Filter"
    iwiener = NormalizeColumnGains(img, Plot=1, Method=Method, Wiener=1)
    print "DR + Image Column  + Wiener mean and standard deviation:  %s    and    %s  " % (
        np.mean(iwiener), np.std(iwiener))

    # Plotting
    pylab.figure(num=None,
                 figsize=(13, 7),
                 dpi=80,
                 facecolor='w',
                 edgecolor='k')
    pylab.subplot(2, 2, 1)
    pylab.imshow(np.multiply(img, 4),
                 cmap=None,
                 norm=None,
                 aspect=None,
                 interpolation='nearest',
                 vmin=0,
                 vmax=2048,
                 origin='upper')
    pylab.title('Original Image')

    pylab.subplot(2, 2, 2)
    pylab.imshow(np.multiply(i2, 4),
                 cmap=None,
                 norm=None,
                 aspect=None,
                 interpolation='nearest',
                 vmin=0,
                 vmax=2048,
                 origin='upper')
    pylab.title("Dark Row normalization Using " + Method)

    pylab.subplot(2, 2, 3)
    pylab.imshow(np.multiply(i3, 4),
                 cmap=None,
                 norm=None,
                 aspect=None,
                 interpolation='nearest',
                 vmin=0,
                 vmax=2048,
                 origin='upper')
    pylab.title('DR and Img Col Using ' + Method)

    pylab.subplot(2, 2, 4)
    #    pylab.imshow(np.multiply(iwiener,4), cmap=None, norm=None, aspect=None, interpolation='nearest', vmin=0, vmax=2048, origin='upper')
    #    pylab.title('Adding Wiener Filter to ' + Method)
    #    oldmean=centroid.frobomad(img, axis=0)[0]
    #    newmean=centroid.frobomad(i3, axis=0)[0]
    oldmean = np.mean(img, axis=0)
    newmean = np.mean(i3, axis=0)
    pylab.plot(oldmean)

    pylab.plot(newmean)
    pylab.legend(
        ['Before Normalization Col RMean', 'After Normalization Col RMean'])
    pylab.xlabel('Column')
    pylab.ylabel('Mean')

    imgutil.dispimg(i3, viewfactor=4.)
    pylab.title('DR + IMGnorm')
    imgutil.dispimg(iwiener, viewfactor=4.)
    pylab.title('DR + IMGnorm + Wiener')

    return i3