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

This brings in the channel swapping function #26

Merged
merged 8 commits into from
May 6, 2016
Merged
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
13 changes: 10 additions & 3 deletions mac/pyrgb/display/rgbdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,18 @@ def __init__(self, argv):
self.lay_inputs.addWidget(self.p0label, 0, 4)
self.p0 = QtGui.QComboBox()
self.lay_inputs.addWidget(self.p0, 0, 5)
self.p0.activated.connect( self.changeChannelViewed )

self.p1label = QtGui.QLabel("G:")
self.lay_inputs.addWidget(self.p1label, 1, 4)
self.p1 = QtGui.QComboBox()
self.p1.activated.connect( self.changeChannelViewed )
self.lay_inputs.addWidget(self.p1, 1, 5)

self.p2label = QtGui.QLabel("B:")
self.lay_inputs.addWidget(self.p2label, 2, 4)
self.p2 = QtGui.QComboBox()
self.p2.activated.connect( self.changeChannelViewed )
self.lay_inputs.addWidget(self.p2, 2, 5)

self.planes = [self.p0, self.p1, self.p2]
Expand Down Expand Up @@ -385,7 +388,6 @@ def plotData(self):

# update channel combo boxes
nchs = self.dm.get_nchannels(event, self.image_producer)
print "Set the RGB drop boxes: ", nchs, " current count=", self.p0.count()
if self.p0.count() != (nchs + 1):
self.p0.clear()
self.p1.clear()
Expand Down Expand Up @@ -472,15 +474,15 @@ def regionChanged(self):

# use mask to updated only pixels not already updated
if self.cv2_layout.overwrite == False:
self.image.orig_mat[idx] = pcopy[idx]
self.image.orig_mat[idx] = pcopy[idx] # reverts prev. modified pixels, preventing double change
self.modimage[sl] = 1

if self.cv2_layout.transform == False:
return

self.pimg = self.image.set_plot_mat(self.iimin,self.iimax)

self.imi.setImage(self.pimg)
self.imi.setImage(self.pimg) # send it back to the viewer

# For now this is fine....

Expand Down Expand Up @@ -552,6 +554,11 @@ def drawBBOX(self, kType):
self.plt.addItem(r1)
self.boxes.append(r1)

def changeChannelViewed(self):
self.setViewPlanes()
self.pimg = self.image.swap_plot_mat( self.iimin, self.iimax, self.views )
self.imi.setImage(self.pimg)

def load_current_image(self):
print "Loading current image!"
# revert the image back to Image2D.nd_array style (possibly
Expand Down
7 changes: 4 additions & 3 deletions mac/pyrgb/lib/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ def get_nchannels(self,ii,imgprod) :
imdata = self.iom.get_data(larcv.kProductImage2D,imgprod)
return imdata.Image2DArray().size()

def get_event_image(self,ii,imgprod,roiprod,planes) :
def get_event_image(self,ii,imgprod,roiprod,planes, refresh=True) :

#Load data in TChain
self.iom.read_entry(ii)

hasroi = False
if roiprod is not None:
roidata = self.iom.iom.get_data(larcv.kProductROI,roiprod)
roidata = roidata.ROIArray()
hasroi = True

imdata = self.iom.get_data(larcv.kProductImage2D,imgprod)

imdata = self.iom.get_data(larcv.kProductImage2D,imgprod) # goes to disk

self.run = imdata.run()
self.subrun = imdata.subrun()
Expand Down
48 changes: 42 additions & 6 deletions mac/pyrgb/lib/image_types/ch12image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,64 @@


class Ch12Image(PlotImage):
# notes
# orig_mat is the ndarray representation of image2d data
# plot_mat is modified to have overlays
# when loading, we manip orig_mat to have the orientation we want
# before going to caffe, __revert_image__ is called to rearrange the image

def __init__(self, img_v, roi_v, planes):
super(Ch12Image, self).__init__(img_v, roi_v, planes)
self.name = "Ch12Image"

def __create_mat__(self):

# compressed images all have the same shape
# this 12 ch data (from the lmdb) was made before the current convention
# thus it stores its data in time order (rather than reverse time order)
# it also has transposed the matrix
# to make sure the final orientation that is sent to caffe
# is correct while also keeping to this display's conventions
# we 1) do not time reverse it, 2) then transpose
# tmw has checked that this is correct

# working copy
if not hasattr(self,'work_mat'):
self.work_mat = np.zeros(list(self.img_v[0].shape)+[len(self.img_v)])

#compressed images all have the same shape
self.orig_mat = np.zeros(list(self.img_v[0].shape) + [3])

for p, fill_ch in enumerate(self.planes):

self.work_mat[:,:,p] = self.img_v[fill_ch]
if fill_ch == -1: continue

self.orig_mat[:, :, p] = self.img_v[fill_ch]

self.idx[fill_ch] = p

self.orig_mat = self.orig_mat[:, ::-1, :]
#self.orig_mat = self.orig_mat[:, ::-1, :]
self.work_mat = np.transpose( self.work_mat, (1,0,2) )
self.orig_mat = np.transpose( self.orig_mat, (1,0,2) )


def __swap_mat_channels__(self,imin,imax,newchs):
print "swap channels to: ",newchs
# store the current state of the orig_mat into the working matrix
for p,ch in enumerate(self.planes):
if ch!=-1:
self.work_mat[:,:,ch] = self.orig_mat[:,:,p] # don't put a blank in there
# swap the planes
self.planes = newchs
# put work mat values into orig_mat
for p,ch in enumerate(self.planes):
if ch!=-1:
self.orig_mat[:,:,p] = self.work_mat[:,:,ch]
else:
self.orig_mat[:,:,p] = np.zeros( (self.orig_mat.shape[0],self.orig_mat.shape[1] ) )
# make the viewing plot_mat and return
return self.__set_plot_mat__(imin,imax)

def __set_plot_mat__(self, imin, imax):


self.plot_mat = self.orig_mat.copy()

# do contrast thresholding
Expand All @@ -40,7 +76,7 @@ def __set_plot_mat__(self, imin, imax):

# revert back to how image was in ROOTFILE for caffe...
def __revert_image__(self):
self.orig_mat = self.orig_mat[:,::-1,:]
self.orig_mat = np.transpose( self.orig_mat, (1,0,2) )

def __create_rois__(self):

Expand Down
4 changes: 4 additions & 0 deletions mac/pyrgb/lib/image_types/plotimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def __revert_image__(self):
def set_plot_mat(self,imin,imax):
return self.__set_plot_mat__(imin,imax)

# rswap channels that are shown
def swap_plot_mat(self,imin,imax,planes):
return self.__swap_mat_channels__(imin,imax,planes)

# create the ROIs if they exists and return them
def parse_rois(self):
self.__create_rois__()
Expand Down
14 changes: 12 additions & 2 deletions mac/pyrgb/rgb_caffe/testwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def prep_image(self):
im[:,:,ix] -= mean

#image is already thresholded according to the user
im[ im < self.config['imin'] ] = self.config['imin']
im[ im > self.config['imax'] ] = self.config['imax']
#im[ im < self.config['imin'] ] = self.config['imin']
#im[ im > self.config['imax'] ] = self.config['imax']

return im

Expand Down Expand Up @@ -152,6 +152,16 @@ def forward_result(self):

self.scores = scores
print "Scores: {}".format(scores)

if "save_datablob" in self.config and self.config["save_datablob"]==True:
print "SAVING DATA BLOB TO FILE"
# we dump the data array the network has in it's blob to a numpy binary file
# this is useful for sanity-checks
if not hasattr(self,'data_numpy_outfile'):
self.data_numpy_outfile = file('saved_data_blobs.npz','w')
data_blob = self.net.blobs["data"].data
np.savez( self.data_numpy_outfile, data_blob )



def __generate_model__(self):
Expand Down
3 changes: 3 additions & 0 deletions mac/ubresnet_12ch_768.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ lastfc: probt

# This layer doesn't have to be here but that's OK, what is the name of the loss layer
loss: loss

# For Debug: save the data given to the network in a numpy binary file
save_datablob: True