Move optparser in front of curses. Add windowing. Make persistence more realistic.

Move the option parser outside the curses wrapper, so it works with the -h help
messages.

Change persistence so that is stacks PSF, rather than stacking antenna locations
(in real-life, this would be adding points on a uv plane corresponding to baselines
between an antenna and itself (and others) at previous times.

Reduce the gaussian width for prettiness, since the above change makes the PSF
worse.

Add experimental windowing function. Currently there's a bug somewhere that means
when windowing is on the scale of the PSF changes. Perhaps fix this, and change
the entire code to stack baseline distribution rather than PSF?

Misc changes to Hough circle detection. Should probably just make these a command line
parameter.
main
Jack 7 years ago
parent 3c04dada84
commit b54446e04b
  1. 62
      gen_psf_interferometer_detect_skyim.py

@ -24,23 +24,14 @@ def fast_conv(image, psf):
imageDirty=np.fft.irfft2(np.fft.rfft2(image, (n,m)) * np.fft.rfft2(psf, (n,m)))
return imageDirty[psf.shape[0]/2:image.shape[0]+psf.shape[0]/2,psf.shape[1]/2:image.shape[1]+psf.shape[1]/2]
def main(stdscr):
o = optparse.OptionParser()
o.set_usage('%prog [options]')
o.set_description(__doc__)
o.add_option('-i','--input',dest='input', default=None,
help='Input \'sky\' image, Default: HARDCODED')
o.add_option('-c','--camera',dest='camera', default=1, type='int',
help='Camera device ID in /dev/video*, Default: 1')
o.add_option('-r','--res',dest='res', default=4, type='int',
help='Resolution factor, increase this value to decrease the resolution, Default: 4')
opts, args = o.parse_args(sys.argv[1:])
def main(stdscr, opts, args):
CAMERA_DEVICE_INDEX=opts.camera #check /dev/, ID is attached to video device (0 is in the internal)
cv2.namedWindow("Antenna Layout", cv2.CV_WINDOW_AUTOSIZE)
cv2.namedWindow("Target Image", cv2.CV_WINDOW_AUTOSIZE)
cv2.namedWindow("Point Spread", cv2.CV_WINDOW_AUTOSIZE)
#cv2.namedWindow("Baseline Distribution", cv2.CV_WINDOW_AUTOSIZE)
cv2.namedWindow("Observed Image", cv2.CV_WINDOW_AUTOSIZE)
cam0 = cv2.VideoCapture(CAMERA_DEVICE_INDEX)
@ -50,6 +41,7 @@ def main(stdscr):
else:
target_image=cv2.imread(opts.input)
target_img_grey = cv2.cvtColor(target_image,cv2.COLOR_BGR2GRAY)
target_img_grey[target_img_grey < 100] = 0
cv2.imshow("Target Image", target_img_grey)
RESCALE_FACTOR=opts.res #decrease to change the effective resolution
@ -59,7 +51,7 @@ def main(stdscr):
#make a 2D Gaussian to modulate the PSF with
def gauss2d(x0,y0,amp,stdx,stdy):
return lambda x,y: amp*np.exp(-1.*( (((x-x0)**2.)/(2*stdx**2.)) + (((y-y0)**2.)/(2*stdy**2.)) ))
gaussFunc=gauss2d(0.,0.,1.,60.,60.)
gaussFunc=gauss2d(0.,0.,1.,40.,40.)
xx = np.arange(xsize)-(xsize/2)
yy = np.arange(ysize)-(ysize/2)
xv, yv = np.meshgrid(xx, yy)
@ -70,6 +62,7 @@ def main(stdscr):
stdscr.clear()
stdscr.addstr('Controls: Quit (q), Pause (p), Toggle Persistence (r)\n')
persistence = False
window = False
while(True):
# Grab 4 images. The images are buffered, so this helps
# get one that is relatively recent. My cv2 doesn't
@ -87,8 +80,8 @@ def main(stdscr):
# set the station locations to zero for each loop, unless we have persistence, in which
# case leave the ones from the previous iteration in
if not persistence:
station_locs = np.zeros([ysize/RESCALE_FACTOR,xsize/RESCALE_FACTOR])
station_overlay = np.zeros_like(layout_img_grey)
station_locs = np.zeros([ysize/RESCALE_FACTOR,xsize/RESCALE_FACTOR])
#cv2.HoughCircles(image, method, dp, minDist, circles, param1, param2, minRadius, maxRadius)
# image: input webcam image size
# method: only cv.CV_HOUGH_GRADIENT exists
@ -99,7 +92,7 @@ def main(stdscr):
# param2: The smaller it is, the more false circles may be detected.
# minRadius: Minimum circle radius
# maxRadius: Maximum circle radius
circles = cv2.HoughCircles(layout_img_grey, cv2.cv.CV_HOUGH_GRADIENT,2,50,None,100,40,15,30)
circles = cv2.HoughCircles(layout_img_grey, cv2.cv.CV_HOUGH_GRADIENT,2,50,None,50,30,15,30)
if circles is not None:
for cn,circle in enumerate(circles[0]):
x,y = circle[1],circle[0]
@ -111,21 +104,33 @@ def main(stdscr):
# draw white squares at the station locations
layout_img_grey[station_overlay==1] = 255
if not persistence:
psf = np.zeros([ysize, xsize])
psf += np.fft.fftshift(np.abs(np.fft.fft2(station_locs,s=[ysize,xsize]))**2)
psf = np.fft.fftshift(np.abs(np.fft.fft2(station_locs,s=[ysize,xsize]))**2)
#psf=psf[(ysize/2)-64:(ysize/2)+64,(xsize/2)-64:(xsize/2)+64] #only select the central region of the PSF
if psf.max() != 0:
psf *= (gaussGrid/psf.max()) #apply a Gaussian taper to the PSF
if window:
bls = np.fft.ifft2(np.fft.fftshift(psf))
abs_bls = np.abs(bls)
abs_bls[0,0] = 0
abs_bls[abs_bls < 0.5] = 1e9
win_psf = np.abs(np.fft.fftshift(np.fft.fft2(bls/abs_bls, s=[ysize,xsize])))
psf_norm = (win_psf*gaussGrid/win_psf.max())
else:
psf_norm = (psf*gaussGrid/psf.max()) #apply a Gaussian taper to the PSF
else:
psf_norm = psf
#target_arr = target_img_grey[:,:]
dirty_arr = fast_conv(target_img_grey, psf)
dirty_arr = fast_conv(target_img_grey, psf_norm)
if dirty_arr.max() != 0:
dirty_arr /= dirty_arr.max()
cv2.imshow("Antenna Layout",layout_img_grey)
cv2.imshow("Point Spread",psf)
cv2.imshow("Point Spread",psf_norm)
cv2.imshow("Observed Image",dirty_arr)
# Key command handling
@ -142,6 +147,7 @@ def main(stdscr):
if k2 != -1:
stdscr.addstr('Unpausing...\n')
break
cv2.waitKey(1)
time.sleep(0.25)
elif k == ord('r'):
if persistence:
@ -149,6 +155,12 @@ def main(stdscr):
else:
stdscr.addstr('Turning Persistence on\n')
persistence = not persistence
elif k == ord('w'):
if window:
stdscr.addstr('Turning window off\n')
else:
stdscr.addstr('Turning window on\n')
window = not window
cv2.waitKey(1)
@ -156,4 +168,14 @@ def main(stdscr):
cv2.destroyAllWindows()
if __name__ == "__main__":
curses.wrapper(main)
o = optparse.OptionParser()
o.set_usage('%prog [options]')
o.set_description(__doc__)
o.add_option('-i','--input',dest='input', default=None,
help='Input \'sky\' image, Default: HARDCODED')
o.add_option('-c','--camera',dest='camera', default=1, type='int',
help='Camera device ID in /dev/video*, Default: 1')
o.add_option('-r','--res',dest='res', default=4, type='int',
help='Resolution factor, increase this value to decrease the resolution, Default: 4')
opts, args = o.parse_args(sys.argv[1:])
curses.wrapper(main, opts, args)

Loading…
Cancel
Save