Skip to content

Commit

Permalink
updates to photoshop
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Genty committed May 2, 2016
1 parent 50421dd commit c18babe
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 34 deletions.
86 changes: 63 additions & 23 deletions mac/pyrgb/display/cv2display.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ def __init__(self):
self.enabled = False
self.cv2 = None
self.imi = None
# this should save users from having to load
# opencv if they don't want to...
self.overwrite = False
self.transform = True

# this should save users from having to load
# opencv if they don't want to...


def enable(self):

Expand Down Expand Up @@ -42,37 +45,66 @@ def enable(self):
for selection in self.selector.selections: #its a dict
self.comboBoxSelector.addItem(selection)

self.lay_inputs.addWidget(self.comboBoxSelector,1,0)
self.lay_inputs.addWidget(self.comboBoxSelector,0,1)

self.setSelection()

self.option = QtGui.QLabel("<b>Options</b>")
self.lay_inputs.addWidget(self.option,0,1)

self.tf = QtGui.QCheckBox("Transform")
self.tf.setChecked(True)
self.lay_inputs.addWidget( self.tf, 1, 0 )
self.tf.stateChanged.connect(self.setTransform)
self.setTransform()

self.ow = QtGui.QCheckBox("Overwrite")
self.ow.setChecked(False)
self.lay_inputs.addWidget( self.ow, 1, 1 )
self.ow.stateChanged.connect(self.setOverwrite)
self.setOverwrite()

# self.option = QtGui.QLabel("<b>Options</b>")
# self.lay_inputs.addWidget(self.option,0,1)

self.changed = False

self.menu = {}
self.setMenu()


self.loaded = QtGui.QPushButton("Reload!")
self.lay_inputs.addWidget(self.loaded,2,0)
self.loaded.clicked.connect(self.reLoad)

self.enabled = True


def setTransform(self):
if self.tf.isChecked():
self.transform = True
else:
self.transform = False


def setOverwrite(self):
if self.ow.isChecked():
self.overwrite = True
else:
self.overwrite = False


def reLoad(self):

self.changed = True
print "reloaded... {} {}".format(str(self.comboBoxSelector.currentText()),
self.selected)
self.selected)

if str(self.comboBoxSelector.currentText()) != self.selected:
self.setSelection()
self.setMenu()


def setMenu(self):

c = 1
c = 2
if len(self.menu) != 0:
for item in self.menu:
#explicitly get rid of these fuckers
Expand All @@ -86,14 +118,14 @@ def setMenu(self):
self.menu = {}

for op,ty in self.selector.selection.options.iteritems():
l = QtGui.QLabel(op)
o = self.set_type(ty)
t = type(ty)
l = QtGui.QLabel(op)
t = self.selector.selection.types[op]
o = self.set_type(ty,t)

self.lay_inputs.addWidget(l,1,c)
self.lay_inputs.addWidget(o,2,c)

self.menu[op] = (l,o,ty)
self.menu[op] = (l,o,t)

c+=1

Expand Down Expand Up @@ -127,13 +159,14 @@ def paint(self,sl): #sl == slice of pimg
self.imi.setImage(sl)
return sl

def set_type(self,option):
def set_type(self,option,ty):
qte = QtGui.QLineEdit()
qte.setFixedHeight(len(option)*10)
qte.setFixedHeight(5*10)
qte.setFixedWidth(75)

text = ""

if type(option) == tuple:
if ty is tuple:
text = "("
for o in option:
text += str(o) + ","
Expand All @@ -143,22 +176,29 @@ def set_type(self,option):
qte.setText(text)
return qte

raise exception("Please implement type: {} in set_type cv2display".format(type(option)))
if ty is int:
qte.setText(str(option))
return qte

if ty is float:
qte.setText(str(option))
return qte

raise Exception("Please implement type: {} in set_type cv2display".format(type(option)))

def convert(self,tu):

if type(tu[1]) == tuple:
if tu[1] is tuple:
t = tu[0][1:-1].split(",")
return tuple([int(i) for i in t])

if type(tu[1]) == int:
return int(tu[1])

if tu[1] is int:
return int(tu[0])

if type(tu[1]) == float:
return float(tu[1])
if tu[1] is float:
return float(tu[0])

if type(tu[1]) == list:
if tu[1] is list:

t = tu[0].split(",")

Expand Down
35 changes: 27 additions & 8 deletions mac/pyrgb/display/rgbdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def __init__(self,argv):
self.chosenImageProducer()
self.chosenROIProducer()

self.pimg = None
self.pimg = None
self.modimg = None

self.rgbcaffe.clicked.connect( self.expandWindow )
self.rgbcv2.clicked.connect( self.openCVEditor )
Expand Down Expand Up @@ -305,7 +306,8 @@ def autoRange(self):

if self.cv2_enabled == True:
self.plt.addItem(self.swindow)
self.swindow.setZValue(10)
self.swindow.setZValue(10)
self.modimage = None

def which_type(self):

Expand Down Expand Up @@ -377,7 +379,8 @@ def plotData(self):

# Emplace the image on the canvas
self.imi.setImage(self.pimg)

self.modimage = None

if self.rois is None:
self.autoRange()
return
Expand Down Expand Up @@ -454,9 +457,6 @@ def drawBBOX(self,kType):
w_b = bbox.max_x() - bbox.min_x()
h_b = bbox.max_y() - bbox.min_y()

# print "bbox bl().x {} bbox bl().y {} imm bl().x {} imm bl().y {}".format(bbox.bl().x,bbox.bl().y,imm.bl().x,imm.bl().y)

#Set the text
ti = pg.TextItem(text=STORAGE.particle_types[ roi_p['type'] ])
ti.setPos( x*dw_i , ( y + h_b )*dh_i + 1 )

Expand All @@ -474,8 +474,27 @@ def drawBBOX(self,kType):
self.boxes.append(r1)

def regionChanged(self):
sl = self.swindow.getArraySlice(self.pimg,self.imi)
self.pimg[ sl[0] ] = self.cv2_display.paint(self.pimg[ sl[0] ])

if self.modimage is None:
self.modimage = np.zeros( list(self.pimg.shape) )

sl = self.swindow.getArraySlice(self.pimg,self.imi)[0]

# need mask if user doesn't want to overwrite
if self.cv2_display.overwrite == False:
idx = np.where( self.modimage == 1 )
pcopy = self.pimg.copy()

self.pimg[ sl ] = self.cv2_display.paint( self.pimg[ sl ] ) ##11,11,3

# use mask to updated only pixels not already updated
if self.cv2_display.overwrite == False:
self.pimg[ idx ] = pcopy[ idx ]
self.modimage[ sl ] = 1

if self.cv2_display.transform == False:
return

self.imi.setImage(self.pimg)


Expand Down
15 changes: 15 additions & 0 deletions mac/pyrgb/rgb_cv2/cv2add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from cv2selection import CV2Selection

class CV2Add(CV2Selection):
def __init__(self):
super(CV2Add,self).__init__()

self.name = "CV2Add"
self.options['add'] = int(0)
self.types['add'] = int

def __description__(self):
return "No description provided!"

def __implement__(self,image):
return self.options['add'] + image
5 changes: 4 additions & 1 deletion mac/pyrgb/rgb_cv2/cv2blur.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ def __init__(self):

# default options
self.options['ksize'] = (5,5)
self.options['anchor'] = (-1,-1)
self.options['anchor'] = (-1,-1)

self.types['ksize'] = tuple
self.types['anchor'] = tuple

def __description__(self):
return "No description provided!"

Expand Down
15 changes: 15 additions & 0 deletions mac/pyrgb/rgb_cv2/cv2multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from cv2selection import CV2Selection

class CV2Multiply(CV2Selection):
def __init__(self):
super(CV2Multiply,self).__init__()

self.name = "CV2Multiply"
self.options['multiply'] = float(1)
self.types['multiply'] = float

def __description__(self):
return "No description provided!"

def __implement__(self,image):
return self.options['multiply'] * image
1 change: 1 addition & 0 deletions mac/pyrgb/rgb_cv2/cv2selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class CV2Selection(object):
def __init__(self):
self.name = "CV2Selection"
self.options = {}
self.types = {}

def description(self):
return self.__description__()
Expand Down
8 changes: 6 additions & 2 deletions mac/pyrgb/rgb_cv2/cv2selector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from cv2blur import CV2Blur
from cv2nothing import CV2Nothing
from cv2add import CV2Add
from cv2multiply import CV2Multiply

class CV2Selector(object):
def __init__(self):
self.selections = { "nothing" : CV2Nothing(),
"blur" : CV2Blur() }
self.selections = { "nothing" : CV2Nothing(),
"blur" : CV2Blur() ,
"add" : CV2Add(),
"multiply" : CV2Multiply()}

self.selection = None

Expand Down

0 comments on commit c18babe

Please sign in to comment.