def create_blank_image_as(img): image = vl.VglImage(img.filename, img.depth, img.ndim, img.clForceAsBuf) image.ipl = np.asarray(img.ipl, img.ipl.dtype) image.shape = img.shape image.vglShape = img.vglShape image.depth = img.depth image.nChannels = img.nChannels image.has_mipmap = img.has_mipmap image.inContext = vl.VGL_BLANK_CONTEXT() return image
""" 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()
""" CL.IMAGE OBJECTS """ img_in_path = sys.argv[1] nSteps = int(sys.argv[2]) img_out_path = sys.argv[3] print("in path", img_in_path) print("steps", nSteps) print("out path", img_out_path) msg = "" vl.vglClInit() img_input_3d = vl.VglImage(img_in_path, None, vl.VGL_IMAGE_3D_IMAGE()) vl.vglLoadImage(img_input_3d) vl.vglClUpload(img_input_3d) img_output_3d = vl.create_blank_image_as(img_input_3d) img_output_3d.set_oclPtr(vl.get_similar_oclPtr_object(img_input_3d)) vl.vglAddContext(img_output_3d, vl.VGL_CL_CONTEXT()) convolution_window_3d_3x3x3 = np.ones((3, 3, 3), np.float32) * (1 / 27) convolution_window_3d_5x5x5 = np.ones((5, 5, 5), np.float32) * (1 / 125) vglCl3dBlurSq3(img_input_3d, img_output_3d) media = 0.0 for i in range(0, 5): p = 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)
#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) cl.enqueue_copy(wrp.cl_ctx.queue, img_out_aux, img_output.get_oclPtr())
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()) vl.vglSaveImage("yamamoto-vglNdCopy.jpg", img_output)
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),
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)