def DrawROI(self):
object = self.object
bmp = self.image.GetBitmap()
w = bmp.GetWidth()
h = bmp.GetHeight()
roi = [0]*6
for i in range(3):
roi[2*i] = int(self.roi[2*i].value.GetValue()) - 1
roi[2*i+1] = int(self.roi[2*i+1].value.GetValue()) - 1
axis = int(self.scrollaxis.value.GetValue())
if axis == 1:
rx = int(float(w*roi[4])/float(object.shape[2]) +0.5)
rw = int(float(w*(roi[5] - roi[4] +1.0))/float(object.shape[2]) +0.5)
ry = int(float(h*roi[2])/float(object.shape[1]) +0.5)
rh = int(float(h*(roi[3] - roi[2] +1.0))/float(object.shape[1]) +0.5)
elif axis == 2:
rx = int(float(w*roi[4])/float(object.shape[2]) +0.5)
rw = int(float(w*(roi[5] - roi[4] +1.0))/float(object.shape[2]) +0.5)
ry = int(float(h*roi[0])/float(object.shape[0]) +0.5)
rh = int(float(h*(roi[1] - roi[0] +1.0))/float(object.shape[0]) +0.5)
elif axis == 3:
rx = int(float(w*roi[2])/float(object.shape[1]) +0.5)
rw = int(float(w*(roi[3] - roi[2] +1.0))/float(object.shape[1]) +0.5)
ry = int(float(h*roi[0])/float(object.shape[0]) +0.5)
rh = int(float(h*(roi[1] - roi[0] +1.0))/float(object.shape[0]) +0.5)
self.dc = wx.MemoryDC(bmp)
self.dc.SelectObject(bmp)
self.dc.SetPen(wx.Pen(wx.RED, 1))
self.dc.SetBrush(wx.TRANSPARENT_BRUSH)
self.dc.DrawRectangle(rx, ry, rw, rh)
self.dc.SelectObject(wx.NullBitmap)
self.image.SetBitmap(bmp)
self.Layout()
评论列表
文章目录