def salvando2d(img, name): # SAVING IMAGE img ext = name.split(".") ext.reverse() #vl.vglClDownload(img) vl.vglCheckContext(img, vl.VGL_RAM_CONTEXT()) if (ext.pop(0).lower() == 'jpg'): if (img.getVglShape().getNChannels() == 4): vl.rgba_to_rgb(img) vl.vglSaveImage(name, img)
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() vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT()) vl.vglSaveImage("img-vglNdCopy.jpg", img_output) msg = msg + "Tempo de execução do método vglClNdCopy:\t" +str( round( (fim-inicio), 9 ) ) +"s\n" inicio = t.time() vglClNdConvolution(img_input, img_output, window) fim = t.time() vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT()) vl.vglSaveImage("img-vglNdConvolution.jpg", img_output) msg = msg + "Tempo de execução do método vglClNdConvolution:\t" +str( round( (fim-inicio), 9 ) ) +"s\n" inicio = t.time() vglClNdDilate(img_input, img_output, window) fim = t.time() vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT()) vl.vglSaveImage("img-vglNdDilate.jpg", img_output) msg = msg + "Tempo de execução do método vglClNdDilate:\t" +str( round( (fim-inicio), 9 ) ) +"s\n"
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 inicio = t.time() while (p < nSteps): vglCl3dBlurSq3(img_input_3d, img_output_3d) p = p + 1 fim = t.time() media = media + (fim - inicio) vl.vglSaveImage(img_out_path + "3d-vglCl3dBlurSq3.tif", img_output_3d) msg = msg + "Tempo de execução do método vglCl3dBlurSq3:\t\t" + str( round((media / 5), 9)) + "s\n" vglCl3dConvolution(img_input_3d, img_output_3d, convolution_window_3d_3x3x3, np.uint32(3), np.uint32(3), np.uint32(3)) media = 0.0 for i in range(0, 5): p = 0 inicio = t.time() while (p < nSteps): vglCl3dConvolution(img_input_3d, img_output_3d, convolution_window_3d_3x3x3, np.uint32(3), np.uint32(3), np.uint32(3)) p = p + 1
# 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) wrp.vglClNdBinThreshold(img_input, img_output, 100) cl.enqueue_copy(wrp.cl_ctx.queue, img_input.get_oclPtr(), img_output.get_oclPtr()) wrp.vglClNdBinDilate(img_input, img_output, window) cl.enqueue_copy(wrp.cl_ctx.queue, img_input.get_oclPtr(), img_output.get_oclPtr()) wrp.vglClNdBinToGray(img_input, img_output) vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT()) vl.vglSaveImage("bin-vglClNdBinDilate.png", img_output) img_output.set_oclPtr(vl.get_similar_oclPtr_object(img_input)) img_input = vl.VglImage("bin.pgm", vl.VGL_IMAGE_2D_IMAGE(), None, vl.IMAGE_ND_ARRAY()) vl.vglLoadImage(img_input) vl.vglClUpload(img_input) wrp.vglClNdBinThreshold(img_input, img_output, 100) cl.enqueue_copy(wrp.cl_ctx.queue, img_input.get_oclPtr(), img_output.get_oclPtr()) wrp.vglClNdBinDilatePack(img_input, img_output, window) cl.enqueue_copy(wrp.cl_ctx.queue, img_input.get_oclPtr(), img_output.get_oclPtr()) wrp.vglClNdBinToGray(img_input, img_output) vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT())