コード例 #1
0
def getCentroids(fnames):
    '''True
    From a list of filenames, load the filenames, clean up the images, find stars
    in the images, and return a list of centroids and the number of stars found in
    each image.
    '''
    
    n = len(fnames)
    centroids = []
    numstars = []
    for count,fname in enumerate(fnames):
        # Display status:
        print 'Loading and centroiding filename ' + str(count+1) + ' of ' + str(n) + '.'
        
        # Load the image:
        image = imgutil.loadimg(fname,from_database=True)
        
        # Clean up image, if it hasn't been already:
        if not fname.find('_norm.tif'):
            image = flatfield.ImgNormalize(image, Method="mean")
        
        # Find stars in image:
        #centers = centroid.findstars(image)
        # Nighttime:
        centers = centroid.findstars(image,zreject=4, zthresh=3.2, zpeakthresh=5, min_pix_per_star=6, max_pix_per_star=60, oblongness=2,debug=False)
        # Daytime:        
        #centers = centroid.findstars(image,zreject=3, zthresh=3.0, zpeakthresh=4, min_pix_per_star=6, max_pix_per_star=60, oblongness=2,debug=False)
        
        # Get centroids:
        centroids.append(centroid.imgcentroid(image,centers))
        
        # store number of stars centroided per frame
        numstars.append(len(centroids[count]))
        
    return centroids,numstars
コード例 #2
0
def main():

    # Enable import from other dirs in DataAnalysis
    sys.path.append("../")

    # Addtl imports for main script
    from util import imgutil as imgutil
    from util import submethods as subm

    # Load the image:
    image = imgutil.loadimg('/home/sticky/Daystar/img_1348368011_459492_00146_00000_1.dat')
        
    # Get a good estimation for the background level and variance:
    (mean,std) = frobomad(image)

    # Do column subtraction:
    image = subm.colmeansub(image)

    # Find star centroids:
    centroids = findstars(image,std=std,debug=True)
      
          
    # Refine centroids using two methods 
    iwc = imgcentroid(image, centroids, "iwc")
    gauss = imgcentroid(image, centroids, "gauss")
    
    
    print "---"
    for each in centroids:
        print each
    
    print "---"
        
    for each in iwc:
        print each
        
    print "---"
    for each in gauss:
        print each 
    
      
    # Display image:
    #imgutil.dispimg(image,5)

    # Display image with stars circled:
    #imgutil.circstars(image,iwc + gauss,1)
    
    return 0
コード例 #3
0
ファイル: centroid.py プロジェクト: adamnemecek/DataAnalysis
def main():

    # Enable import from other dirs in DataAnalysis
    sys.path.append("../")

    # Addtl imports for main script
    from util import imgutil as imgutil
    from util import submethods as subm

    # Load the image:
    image = imgutil.loadimg(
        '/home/sticky/Daystar/img_1348368011_459492_00146_00000_1.dat')

    # Get a good estimation for the background level and variance:
    (mean, std) = frobomad(image)

    # Do column subtraction:
    image = subm.colmeansub(image)

    # Find star centroids:
    centroids = findstars(image, std=std, debug=True)

    # Refine centroids using two methods
    iwc = imgcentroid(image, centroids, "iwc")
    gauss = imgcentroid(image, centroids, "gauss")

    print "---"
    for each in centroids:
        print each

    print "---"

    for each in iwc:
        print each

    print "---"
    for each in gauss:
        print each

    # Display image:
    #imgutil.dispimg(image,5)

    # Display image with stars circled:
    #imgutil.circstars(image,iwc + gauss,1)

    return 0
コード例 #4
0
def main():

    print 'Loading filenames from database.'
    db = database.Connect()
    data = db.select("select id,raw_fn from rawdata where(norm_fn='0') limit 2000")
    fnames=data.raw_fn.tolist()
    ids=data.id.tolist()

    n = len(fnames)



    for count,fname in enumerate(fnames):
        path=os.environ.get('RawBaseLoc')
        dir_path="/".join((path + fname).split("/")[:-1])+"/norm/"

        if not os.path.isdir(dir_path):
            os.mkdir(dir_path)

#        norm_fn= str.replace(fname,'.dat','_norm.tif')
        full_path=(path+fname).split('/')
        full_path[-1]=str.replace("norm/"+full_path[-1],'.dat','_norm.tif')
        norm_fn='/'.join(full_path[-3:])
        full_path='/'.join(full_path)
        if not os.path.isfile(full_path):


            print "Normalizng " + fname + " image # %s of %s" % (count,n)
            # Load the image:
            image = imgutil.loadimg(fname,from_database=True,load_full=True)

            # Normalize up image:
            image = flatfield.ImgNormalize(image, Method="mean")

            print "Saving normalized image as " + norm_fn
            # Save the image with _norm.tif appended
            imgutil.saveimg(image,full_path)

            del image # Remove from memory to make go faster?

        print "Adding normalized image to database in 'norm_fn': " + full_path
        query="UPDATE rawdata SET norm_fn='"+ norm_fn + "' WHERE(id="+str(ids[count])+")"
        db.execute_statement(query)
コード例 #5
0
from util import submethods as subm
from db import RawData as database
from analysis import flatfield
import time

###################################################################################
# Main
###################################################################################
# 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,
コード例 #6
0
# Jed Diller
# Script to load and save a tiff and dat file
# 10/8/12

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)
コード例 #7
0
# Get the directory above the directory this file is in
sys.path.append(os.path.join(os.path.dirname(__file__), '../'))

# More imports
import numpy as np
import copy as cp
import time

# Addtl imports for main script
from util import imgutil as imgutil
from analysis import submethods as sm
from analysis import centroid as centroid
from analysis import flatfield as flat

# Load the image:
image = imgutil.loadimg('/home/sticky/Daystar/day1.dat')
#image = imgutil.loadimg('/home/sticky/Daystar/img_1348355543_717188_00015_00000_0.dat', 
#                        load_full=True)
#image = imgutil.loadimg('/home/sticky/Daystar/img_1348370070_656182_00172_00000_1.dat')


# Apply flatfield
img1 = flat.ImgNormalize(image, Method="mean", source="image")
#img1 = flat.ImgNormalize(img1, Method="mean", source="image")
img2 = sm.colmeansub(image)

# Find stars
centers = centroid.findstars(img1, zreject=3, zthresh=3.0, zpeakthresh=4, min_pix_per_star=6, max_pix_per_star=60, oblongness=5,debug=False)


C = centroid.imgcentroid(image,centers)
コード例 #8
0
import script_setup
from util import imgutil as imgutil
from analysis import submethods as submethods

import numpy as np

# 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...'
コード例 #9
0
###################################################################################
# Import modules from analysis (the correct way to do it):
###################################################################################
from analysis import centroid as centroid
from db import RawData as database
from analysis import submethods as sm
from util import imgutil as imgutil
import pylab as pl

# ----------------- Plot Different Centroid Methods on Same Star-------------------------------
print 'saving plots of centroid methods on same star'
db = database.Connect()
name = db.select('select raw_fn from rawdata where burst_num = 172 limit 1'
                 ).raw_fn.tolist()[0]
img = imgutil.loadimg(name, from_database=True)
# find good star
centers = centroid.findstars(img)
print centers
goodstar = []
goodstar.append(centers[10])
#goodstar = list((tuple(centers[10])) # good centroid at about 1417,275

(x, y) = goodstar[0][0]
(w, h) = goodstar[0][1]

centroid_iwc = centroid.imgcentroid(img, goodstar, method="iwc")
centroid_cog = centroid.imgcentroid(img, goodstar, method="cog")
centroid_gauss = centroid.imgcentroid(img, goodstar, method="gauss")

(frame, (xframe, yframe), frame_centroid) = sm.windowsub(img, (x, y), (w, h),
コード例 #10
0
import script_setup
from util import imgutil as imgutil
from analysis import submethods as submethods

import numpy as np

# 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
コード例 #11
0
import script_setup

###################################################################################
# Import modules from analysis (the correct way to do it):
###################################################################################
from analysis import centroid as centroid
from db import RawData as database
from analysis import submethods as sm
from util import imgutil as imgutil
import pylab as pl

# ----------------- Plot Different Centroid Methods on Same Star-------------------------------
print 'saving plots of centroid methods on same star'
db = database.Connect()
name = db.select('select raw_fn from rawdata where burst_num = 172 limit 1').raw_fn.tolist()[0]
img = imgutil.loadimg(name,from_database=True)
# find good star
centers = centroid.findstars(img)
print centers
goodstar = []
goodstar.append(centers[10])
#goodstar = list((tuple(centers[10])) # good centroid at about 1417,275

(x,y) = goodstar[0][0]
(w,h) = goodstar[0][1]

centroid_iwc   = centroid.imgcentroid(img, goodstar, method="iwc")
centroid_cog   = centroid.imgcentroid(img, goodstar, method="cog")
centroid_gauss = centroid.imgcentroid(img, goodstar, method="gauss")
        
(frame, (xframe,yframe), frame_centroid) = sm.windowsub(img, (x,y), (w,h), neg=True, scale=1)
コード例 #12
0
from util import imgutil as imgutil
from util import submethods as subm
from db import RawData as database
from analysis import flatfield
import time

###################################################################################
# Main
###################################################################################
# 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
コード例 #13
0
# Jed Diller
# Script to load and save a tiff and dat file
# 10/8/12

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)
コード例 #14
0
    print "Computing quaternions for each image"
    quats,matched_centroids,nummatchstars = getQuaternions(centroids)
    # update quaternions into the database
    print"Inserting quaterninos, number of matched stars, and matched stars into the database"
    for count,q in enumerate(quats):
        db.insert_quat(q,id[count])
        db.insert_num_matched_centroids(nummatchstars[count],id[count])
        db.insert_matched_centroids([matched_centroids[count]],id[count])



print 'Find yaw, pitch, and roll rms.'
# Get the roll, pitch, yaw variances:
delta_t = 0.1 # s
motion_frequency = 3.5 # Hz
var_y,var_p,var_r,a,b,c = tracking.FindVariance(quats,delta_t=delta_t,motion_frequency=motion_frequency,plot=plot)
toc = time.clock()
print 'YPR rms: ',np.sqrt(var_y),np.sqrt(var_p),np.sqrt(var_r)
print 'Total time: ' + str(toc - tic) + ' s'
 
#############################################################
# Plots:
#############################################################
if plot:
    image0 = imgutil.loadimg(fnames[0],from_database=True)
    plots.starnum(numstars)
    plots.starnum(nummatchstars)
    plots.starpaths(image0,centroids)
    plots.starpaths(image0,matched_centroids)
    
コード例 #15
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
コード例 #16
0
ファイル: flatfield.py プロジェクト: adamnemecek/DataAnalysis
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