Esempio n. 1
0
def create_vglShape(img):
	if(img.ipl is not None):
		print("-> create_vglShape: Starting")

		img.vglShape = vl.VglShape()
		if( img.ndim == vl.VGL_IMAGE_2D_IMAGE() ):
			#print("2D Image")
			if( len(img.ipl.shape) == 2 ):
				# SHADES OF GRAY IMAGE
				#print("VglImage LUMINANCE")
				img.vglShape.constructor2DShape(1, img.ipl.shape[1], img.ipl.shape[0])
			elif(len(img.ipl.shape) == 3):
				# MORE THAN ONE COLOR CHANNEL
				#print("VglImage RGB")
				img.vglShape.constructor2DShape(img.ipl.shape[2], img.ipl.shape[1], img.ipl.shape[0])
		elif( img.ndim == vl.VGL_IMAGE_3D_IMAGE() ):
			#print("3D Image")
			if( len(img.ipl.shape) == 3 ):
				# SHADES OF GRAY IMAGE
				#print("VglImage LUMINANCE")
				img.vglShape.constructor3DShape( 1, img.ipl.shape[2], img.ipl.shape[1], img.ipl.shape[0] )
			elif(len(img.ipl.shape) == 4):
				# MORE THAN ONE COLOR CHANNEL
				#print("VglImage RGB")
				img.vglShape.constructor3DShape( img.ipl.shape[3], img.ipl.shape[2], img.ipl.shape[1], img.ipl.shape[0] )
		else:
			print("vglImage: create_vglShape Error: image dimension not recognized. img.ndim:", img.ndim)
			exit()
	else:
		print("vglImage: create_vglShape Error: img.ipl is None. Please, load image first!")
		exit()
	print("<- create_vglShape: Ending\n")
Esempio n. 2
0
	def __init__(self, imgPath="", depth=None, ndim=None, clForceAsBuf=None ):
		# IF THE IMAGE TYPE IS NOT SPECIFIED, A 2D IMAGE WILL BE ASSUMED
		# INICIALIZING DATA
		self.ipl = None
		self.ndim = ndim
		self.shape = np.zeros((2*vl.VGL_MAX_DIM()), np.uint8)
		self.vglShape = None
		self.depth = depth
		self.nChannels = 0
		self.has_mipmap = 0
		self.oclPtr = None
		self.clForceAsBuf = clForceAsBuf
		self.inContext = 0
		self.filename = imgPath

		# NOT IMPLEMENTED IN PYTHON-SIDE
		self.fbo = -1
		self.tex = -1

		self.cudaPtr = None
		self.cudaPbo = -1

		if( self.depth == None ):
			self.depth = vl.IPL_DEPTH_1U()

		if( self.clForceAsBuf is None ):
			self.clForceAsBuf = vl.IMAGE_CL_OBJECT()
		elif( not((self.clForceAsBuf is vl.IMAGE_CL_OBJECT() )
			   or (self.clForceAsBuf is vl.IMAGE_ND_ARRAY() ) ) ):
			print("VglImage: Error! Unexistent image treatment. Use vl.IMAGE_CL_OBJECT() or vl.IMAGE_ND_ARRAY()!")
			exit()

		if(self.ndim is None):
			self.ndim = vl.VGL_IMAGE_2D_IMAGE()
			print(":Assuming 2D Image!")
		elif(self.ndim is vl.VGL_IMAGE_2D_IMAGE()):
			print(":Creating 2D Image!")
		elif(self.ndim is vl.VGL_IMAGE_3D_IMAGE()):
			print(":Creating 3D Image!")
		else:
			print("vglImage: Warning! Image is not 2D or 3D. Execution will continue.")
		
		print(":::-->path", imgPath)
		print(":::-->dept", depth)
		print(":::-->ndim", ndim)
		print(":::-->forc", clForceAsBuf)
Esempio n. 3
0
"""
	THIS BENCHMARK TOOL EXPECTS JUST 1 ARGUMENT:

	ARGV[1]: PRIMARY 2D-IMAGE PATH (COLORED OR GRAYSCALE)
		IT WILL BE USED IN ALL KERNELS AS INPUT IMAGE

	THE RESULT IMAGES WILL BE SAVED AS IMG-[PROCESSNAME].JPG
"""
if __name__ == "__main__":
	
	vl.vglClInit()

	msg = ""

	# INPUT IMAGE
	img_input = vl.VglImage(sys.argv[1], None, vl.VGL_IMAGE_2D_IMAGE(), vl.IMAGE_ND_ARRAY())
	vl.vglLoadImage(img_input)
	vl.vglClUpload(img_input)

	# OUTPUT IMAGE
	img_output = vl.create_blank_image_as(img_input)
	img_output.set_oclPtr( vl.get_similar_oclPtr_object(img_input) )
	vl.vglAddContext(img_output, vl.VGL_CL_CONTEXT())

	# STRUCTURANT ELEMENT
	window = vl.VglStrEl()
	window.constructorFromTypeNdim(vl.VGL_STREL_CROSS(), 2)

	inicio = t.time()
	vglClNdCopy(img_input, img_output)
	fim = t.time()
Esempio n. 4
0
    if (ext.pop(0).lower() == 'jpg'):
        if (img.getVglShape().getNChannels() == 4):
            vl.rgba_to_rgb(img)

    vl.vglSaveImage(name, img)


if __name__ == "__main__":

    wrp = cl2py_CL()
    """
		CL.IMAGE OBJECTS
	"""

    img_input = vl.VglImage("bin.pgm", vl.VGL_IMAGE_2D_IMAGE())
    vl.vglLoadImage(img_input)
    #if( img_input.getVglShape().getNChannels() == 3 ):
    #	vl.rgb_to_rgba(img_input)

    vl.vglClUpload(img_input)

    img_input2 = vl.VglImage("bin.pgm", vl.VGL_IMAGE_2D_IMAGE())
    vl.vglLoadImage(img_input2)
    #if( img_input2.getVglShape().getNChannels() == 3 ):
    #	vl.rgb_to_rgba(img_input2)

    #img_input_3d = vl.VglImage("3d.tif", vl.VGL_IMAGE_3D_IMAGE())
    #vl.vglLoadImage(img_input_3d)
    #vl.vglClUpload(img_input_3d)
Esempio n. 5
0
        #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None)
        cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run,
                                   img_output.ipl.shape, None)

        vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())


"""
	HERE FOLLOWS THE KERNEL CALLS
"""
if __name__ == "__main__":

    wrp = cl2py_BIN_ND()

    # INPUT IMAGE
    img_input = vl.VglImage("bin.pgm", vl.VGL_IMAGE_2D_IMAGE(), None,
                            vl.IMAGE_ND_ARRAY())
    vl.vglLoadImage(img_input)
    vl.vglClUpload(img_input)

    img_input2 = vl.VglImage("bin2.pgm", vl.VGL_IMAGE_2D_IMAGE(), None,
                             vl.IMAGE_ND_ARRAY())
    vl.vglLoadImage(img_input2)
    vl.vglClUpload(img_input2)

    # OUTPUT IMAGE
    img_output = vl.create_blank_image_as(img_input)
    img_output.set_oclPtr(vl.get_similar_oclPtr_object(img_input))
    vl.vglAddContext(img_output, vl.VGL_CL_CONTEXT())

    img_out_aux = vl.get_similar_oclPtr_object(img_input)
Esempio n. 6
0
        cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run,
                                   img_output.get_ipl().shape, None)

        vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())


"""
	HERE FOLLOWS THE KERNEL CALLS
"""
if __name__ == "__main__":

    wrp = cl2py_ND()

    # INPUT IMAGE
    img_input = vl.VglImage("img-1.jpg", None, vl.VGL_IMAGE_2D_IMAGE(),
                            vl.IMAGE_ND_ARRAY())
    vl.vglLoadImage(img_input)
    vl.vglClUpload(img_input)

    # OUTPUT IMAGE
    img_output = vl.create_blank_image_as(img_input)
    img_output.set_oclPtr(vl.get_similar_oclPtr_object(img_input))
    vl.vglAddContext(img_output, vl.VGL_CL_CONTEXT())

    # STRUCTURANT ELEMENT
    window = vl.VglStrEl()
    window.constructorFromTypeNdim(vl.VGL_STREL_CROSS(), 2)

    wrp.vglClNdCopy(img_input, img_output)
    vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT())
Esempio n. 7
0

if __name__ == "__main__":
    """
		CL.IMAGE OBJECTS
	"""

    img_in_path = sys.argv[1]
    nSteps = int(sys.argv[2])
    img_out_path = sys.argv[3]

    msg = ""

    vl.vglClInit()

    img_input = vl.VglImage(img_in_path, None, vl.VGL_IMAGE_2D_IMAGE())
    vl.vglLoadImage(img_input)
    if (img_input.getVglShape().getNChannels() == 3):
        vl.rgb_to_rgba(img_input)

    vl.vglClUpload(img_input)

    img_output = vl.create_blank_image_as(img_input)
    img_output.set_oclPtr(vl.get_similar_oclPtr_object(img_input))
    vl.vglAddContext(img_output, vl.VGL_CL_CONTEXT())

    convolution_window_2d_3x3 = np.array(
        ((1 / 16, 2 / 16, 1 / 16), (2 / 16, 4 / 16, 2 / 16),
         (1 / 16, 2 / 16, 1 / 16)), np.float32)
    convolution_window_2d_5x5 = np.array(
        ((1 / 256, 4 / 256, 6 / 256, 4 / 256, 1 / 256),
Esempio n. 8
0
    if (ext.pop(0).lower() == 'jpg'):
        if (img.getVglShape().getNChannels() == 4):
            vl.rgba_to_rgb(img)

    vl.vglSaveImage(name, img)


if __name__ == "__main__":

    wrp = cl2py_CL()
    """
		CL.IMAGE OBJECTS
	"""

    img_input = vl.VglImage("yamamoto.jpg", None, vl.VGL_IMAGE_2D_IMAGE())
    vl.vglLoadImage(img_input)
    if (img_input.getVglShape().getNChannels() == 3):
        vl.rgb_to_rgba(img_input)

    vl.vglClUpload(img_input)

    img_input2 = vl.VglImage("yamamoto-vglClThreshold.jpg", None,
                             vl.VGL_IMAGE_2D_IMAGE())
    vl.vglLoadImage(img_input2)
    if (img_input2.getVglShape().getNChannels() == 3):
        vl.rgb_to_rgba(img_input2)

    img_input_3d = vl.VglImage("3d.tif", None, vl.VGL_IMAGE_3D_IMAGE())
    vl.vglLoadImage(img_input_3d)
    vl.vglClUpload(img_input_3d)