Beispiel #1
0
    def loadImage(self, imgpath):
        print("Opening image to be processed")

        self.vglimage = VglImage(imgpath, vc.VGL_IMAGE_3D_IMAGE())
        self.vglimage.vglImageUpload(self.ctx, self.queue)
        self.img_out_cl = self.vglimage.get_similar_device_image_object(
            self.ctx, self.queue)
Beispiel #2
0
    def __init__(self, imgPath, imgDim=vc.VGL_IMAGE_2D_IMAGE()):
        # IF THE IMAGE TYPE IS NOT SPECIFIED, A 2D IMAGE WILL BE ASSUMED
        # INICIALIZING DATA
        self.imgDim = imgDim
        self.img_host = None
        self.img_device = None
        self.img_sync = False

        self.last_changed_host = False
        self.last_changed_device = False

        if (self.imgDim == vc.VGL_IMAGE_2D_IMAGE()):
            print("Creating 2D Image!")
        elif (self.imgDim == vc.VGL_IMAGE_3D_IMAGE()):
            print("Creating 3D Image!")

        # OPENING IMAGE
        self.set_image_host(imgPath)
Beispiel #3
0
    def get_similar_device_image_object(self, ctx, queue):

        if (self.imgDim == vc.VGL_IMAGE_2D_IMAGE()):
            shape = (self.vglshape.getWidth(), self.vglshape.getHeight())
            mf = cl.mem_flags
            imgFormat = cl.ImageFormat(self.get_toDevice_channel_order(),
                                       self.get_toDevice_dtype())
            img_copy = cl.Image(ctx, mf.WRITE_ONLY, imgFormat, shape)
        elif (self.imgDim == vc.VGL_IMAGE_3D_IMAGE()):
            shape = (self.vglshape.getWidth(), self.vglshape.getHeight(),
                     self.vglshape.getNFrames())
            mf = cl.mem_flags
            imgFormat = cl.ImageFormat(self.get_toDevice_channel_order(),
                                       self.get_toDevice_dtype())
            img_copy = cl.Image(ctx, mf.WRITE_ONLY, imgFormat, shape)

        #print("--> Orig:", self.get_device_image().width, self.get_device_image().height, self.get_device_image().depth)
        #print("--> Copy:", img_copy.width, img_copy.height, img_copy.depth)

        return img_copy
Beispiel #4
0
    def create_vglShape(self):
        if (self.img_host is not None):
            print("The image was founded. Creating vglShape.")

            self.vglshape = VglShape()
            if (self.imgDim == vc.VGL_IMAGE_2D_IMAGE()):
                print("2D Image")
                if (len(self.img_host.shape) == 2):
                    # SHADES OF GRAY IMAGE
                    print("VglImage LUMINANCE")
                    self.vglshape.constructor2DShape(1, self.img_host.shape[1],
                                                     self.img_host.shape[0])
                elif (len(self.img_host.shape) == 3):
                    # MORE THAN ONE COLOR CHANNEL
                    print("VglImage RGB")
                    self.vglshape.constructor2DShape(self.img_host.shape[2],
                                                     self.img_host.shape[1],
                                                     self.img_host.shape[0])
            elif (self.imgDim == vc.VGL_IMAGE_3D_IMAGE()):
                print("3D Image")
                if (len(self.img_host.shape) == 3):
                    # SHADES OF GRAY IMAGE
                    print("VglImage LUMINANCE")
                    self.vglshape.constructor3DShape(1, self.img_host.shape[2],
                                                     self.img_host.shape[1],
                                                     self.img_host.shape[0])
                elif (len(self.img_host.shape) == 4):
                    # MORE THAN ONE COLOR CHANNEL
                    print("VglImage RGB")
                    self.vglshape.constructor3DShape(self.img_host.shape[3],
                                                     self.img_host.shape[2],
                                                     self.img_host.shape[1],
                                                     self.img_host.shape[0])

            self.img_sync = False
            self.last_changed_host = True
            self.last_changed_device = False
        else:
            print(
                "Impossible to create a vglImage object. host_image is None.")