Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugs fix #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Gpyr.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from Lpyr import Lpyr
from namedFilter import namedFilter
from maxPyrHt import maxPyrHt
from .Lpyr import Lpyr
from .namedFilter import namedFilter
from .maxPyrHt import maxPyrHt
import numpy
from corrDn import corrDn
from .corrDn import corrDn

class Gpyr(Lpyr):
filt = ''
Expand All @@ -13,19 +13,19 @@ class Gpyr(Lpyr):
def __init__(self, *args): # (image, height, filter, edges)
self.pyrType = 'Gaussian'
if len(args) < 1:
print "pyr = Gpyr(image, height, filter, edges)"
print "First argument (image) is required"
print("pyr = Gpyr(image, height, filter, edges)")
print("First argument (image) is required")
return
else:
self.image = args[0]

if len(args) > 2:
filt = args[2]
if not (filt.shape == 1).any():
print "Error: filt should be a 1D filter (i.e., a vector)"
print("Error: filt should be a 1D filter (i.e., a vector)")
return
else:
print "no filter set, so filter is binom5"
print("no filter set, so filter is binom5")
filt = namedFilter('binom5')
if self.image.shape[0] == 1:
filt = filt.reshape(1,5)
Expand All @@ -40,8 +40,8 @@ def __init__(self, *args): # (image, height, filter, edges)
else:
self.height = args[1]
if self.height > maxHeight:
print ( "Error: cannot build pyramid higher than %d levels"
% (maxHeight) )
print(( "Error: cannot build pyramid higher than %d levels"
% (maxHeight) ))
return
else:
self.height = maxHeight
Expand Down
30 changes: 15 additions & 15 deletions JBhelpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class struct( object ):
def __init__( self, **kwargs ):
for k, v in kwargs.iteritems():
for k, v in kwargs.items():
setattr( self, k, v )


Expand Down Expand Up @@ -65,7 +65,7 @@ def nbimage( data, vmin = None, vmax = None, vsym = False, saveas = None ):
'''
from IPython.display import display, Image
from PIL.Image import fromarray
from StringIO import StringIO
from io import StringIO
data = rerange( data, vmin, vmax, vsym )
data = data.squeeze()
# try to be smart
Expand Down Expand Up @@ -93,14 +93,14 @@ def nbimageLCVbak( data, vmin = None, vmax = None, vsym = False, saveas = None,
'''
from IPython.display import display, Image, HTML
from PIL.Image import fromarray
from StringIO import StringIO
from io import StringIO
css_styling()
data = rerange( data, vmin, vmax, vsym )
data = data.squeeze()

# try to be smart
if 3 <= data.shape[ 0 ] <= 4:
print 'transposing'
print('transposing')
data = data.transpose( ( 1, 2, 0 ) )

s = StringIO()
Expand Down Expand Up @@ -135,7 +135,7 @@ def nbimageLCVbak2( data, vmin = None, vmax = None, vsym = False, saveas = None,
'''
from IPython.display import display, Image, HTML
from PIL.Image import fromarray
from StringIO import StringIO
from io import StringIO
import base64
from PyQt4 import QtGui
from PyQt4 import QtCore
Expand All @@ -145,7 +145,7 @@ def nbimageLCVbak2( data, vmin = None, vmax = None, vsym = False, saveas = None,
data = data.squeeze()
# try to be smart
if 3 <= data.shape[ 0 ] <= 4:
print 'transposing'
print('transposing')
data = data.transpose( ( 1, 2, 0 ) )
s = StringIO()
fromarray( data ).save( s, 'png' )
Expand All @@ -157,13 +157,13 @@ def nbimageLCVbak2( data, vmin = None, vmax = None, vsym = False, saveas = None,

matrix = numpy.require(data, numpy.uint8, 'C')
(w, h) = matrix.shape
print matrix
print(matrix)
qim = QtGui.QImage(matrix.data, w, h, QtGui.QImage.Format_Indexed8)
qim.ndarray = matrix # do we need this?

# make colormap
incr = (256/nshades)+1
colors = range(0,255,(256/nshades)+1)
colors = list(range(0,255,(256/nshades)+1))
colors[-1] = 255
colctr = -1
for i in range(256):
Expand Down Expand Up @@ -216,7 +216,7 @@ def nbimageLCV( dlist, vmin = None, vmax = None, vsym = False, saveas = None,
'''
from IPython.display import display, Image, HTML
from PIL.Image import fromarray
from StringIO import StringIO
from io import StringIO
import base64
from PyQt4 import QtGui
from PyQt4 import QtCore
Expand Down Expand Up @@ -255,7 +255,7 @@ def nbimageLCV( dlist, vmin = None, vmax = None, vsym = False, saveas = None,

# make colormap
incr = (256/nshades)+1
colors = range(0,255,(256/nshades)+1)
colors = list(range(0,255,(256/nshades)+1))
colors[-1] = 255
colctr = -1
for i in range(256):
Expand Down Expand Up @@ -325,7 +325,7 @@ def showIm( dlist, v = None, zoom = 1, title = "", nshades = 256, ncols = 1):
'''
from IPython.display import display, Image, HTML
from PIL.Image import fromarray
from StringIO import StringIO
from io import StringIO
import base64
from PyQt4 import QtGui
from PyQt4 import QtCore
Expand Down Expand Up @@ -353,9 +353,9 @@ def showIm( dlist, v = None, zoom = 1, title = "", nshades = 256, ncols = 1):
vmin = p1-(p2-p1)/8.0
vmax = p2+(p2-p1)/8.0
else:
print "Error: range of %s is not recognized." % v
print " please use a two element tuple or "
print " 'auto', 'auto2' or 'auto3'"
print("Error: range of %s is not recognized." % v)
print(" please use a two element tuple or ")
print(" 'auto', 'auto2' or 'auto3'")
return

data = rerange( data, vmin, vmax, vsym )
Expand All @@ -377,7 +377,7 @@ def showIm( dlist, v = None, zoom = 1, title = "", nshades = 256, ncols = 1):

# make colormap
incr = (256/nshades)+1
colors = range(0,255,(256/nshades)+1)
colors = list(range(0,255,(256/nshades)+1))
colors[-1] = 255
colctr = -1
for i in range(256):
Expand Down
52 changes: 26 additions & 26 deletions Lpyr.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pyramid import pyramid
from corrDn import corrDn
from namedFilter import namedFilter
from maxPyrHt import maxPyrHt
from upConv import upConv
from showIm import showIm
import JBhelpers
from .pyramid import pyramid
from .corrDn import corrDn
from .namedFilter import namedFilter
from .maxPyrHt import maxPyrHt
from .upConv import upConv
from .showIm import showIm
from . import JBhelpers
import numpy
import math
import matplotlib
Expand All @@ -20,17 +20,17 @@ def __init__(self, *args): # (image, height, filter1, filter2, edges)
if len(args) > 0:
self.image = args[0]
else:
print "pyr = Lpyr(image, height, filter1, filter2, edges)"
print "First argument (image) is required"
print("pyr = Lpyr(image, height, filter1, filter2, edges)")
print("First argument (image) is required")
return

if len(args) > 2:
filt1 = args[2]
if isinstance(filt1, basestring):
if isinstance(filt1, str):
filt1 = namedFilter(filt1)
elif len(filt1.shape) != 1 and ( filt1.shape[0] != 1 and
filt1.shape[1] != 1 ):
print "Error: filter1 should be a 1D filter (i.e., a vector)"
print("Error: filter1 should be a 1D filter (i.e., a vector)")
return
else:
filt1 = namedFilter('binom5')
Expand All @@ -41,11 +41,11 @@ def __init__(self, *args): # (image, height, filter1, filter2, edges)

if len(args) > 3:
filt2 = args[3]
if isinstance(filt2, basestring):
if isinstance(filt2, str):
filt2 = namedFilter(filt2)
elif len(filt2.shape) != 1 and ( filt2.shape[0] != 1 and
filt2.shape[1] != 1 ):
print "Error: filter2 should be a 1D filter (i.e., a vector)"
print("Error: filter2 should be a 1D filter (i.e., a vector)")
return
else:
filt2 = filt1
Expand All @@ -58,8 +58,8 @@ def __init__(self, *args): # (image, height, filter1, filter2, edges)
else:
self.height = args[1]
if self.height > maxHeight:
print ( "Error: cannot build pyramid higher than %d levels"
% (maxHeight) )
print(( "Error: cannot build pyramid higher than %d levels"
% (maxHeight) ))
return
else:
self.height = maxHeight
Expand Down Expand Up @@ -144,8 +144,8 @@ def catBands(self, *args):
# set a pyramid value
def set(self, *args):
if len(args) != 3:
print 'Error: three input parameters required:'
print ' set(band, element(tuple), value)'
print('Error: three input parameters required:')
print(' set(band, element(tuple), value)')
self.pyr[args[0]][args[1][0]][args[1][1]] = args[2]

def reconPyr(self, *args):
Expand All @@ -169,15 +169,15 @@ def reconPyr(self, *args):

maxLev = self.height

if isinstance(levs, (str,basestring)) and levs == 'all':
levs = range(0,maxLev)
if isinstance(levs, str) and levs == 'all':
levs = list(range(0,maxLev))
else:
if (levs > maxLev-1).any():
print ( "Error: level numbers must be in the range [0, %d]." %
(maxLev-1) )
print(( "Error: level numbers must be in the range [0, %d]." %
(maxLev-1) ))
return

if isinstance(filt2, basestring):
if isinstance(filt2, str):
filt2 = namedFilter(filt2)
else:
if len(filt2.shape) == 1:
Expand Down Expand Up @@ -297,11 +297,11 @@ def showPyr(self, pRange = None, gap = 1, scale = None, disp = 'qt'):
av = numpy.mean(band)
stdev = numpy.std(band)
pRange[nind,:] = numpy.array([av-2*stdev, av+2*stdev])
elif isinstance(pRange, basestring):
print "Error: band range argument: %s" % (pRange)
elif isinstance(pRange, str):
print("Error: band range argument: %s" % (pRange))
return
elif pRange.shape[0] == 1 and pRange.shape[1] == 2:
scales = numpy.power( numpy.array( range(0,nind) ), scale)
scales = numpy.power( numpy.array( list(range(0,nind)) ), scale)
pRange = numpy.outer( scales, pRange )
band = self.pyrLow()
pRange[nind,:] = ( pRange[nind,:] + numpy.mean(band) -
Expand Down Expand Up @@ -349,7 +349,7 @@ def showPyr(self, pRange = None, gap = 1, scale = None, disp = 'qt'):
llpos[bnum,:] = ctr - numpy.floor(numpy.array(sz))/2.0
# make position list positive, and allocate appropriate image
llpos = llpos - numpy.ones((nind,1))*numpy.min(llpos)
pind = range(self.height)
pind = list(range(self.height))
for i in pind:
pind[i] = self.band(i).shape
urpos = llpos + pind
Expand Down
Loading