 
 	gaussian_blur_tiled<<<gridSize,blockSize,smemSize>>>(grayImage,d_filter_Image, IMAGE_HEIGHT, IMAGE_WIDTH,d_kernel, filterWidth);
 	cudaDeviceSynchronize();
-	//CudaCheckError();
-	
-	/*
-	thrust::device_ptr<float> dbeg(d_filter_Image);
-	thrust::device_ptr<float> dend = dbeg + NUMPIX;
-	
-	float min, max;
-	find_min_max(dbeg, dend, &min, &max);
-	*/
-
+	CudaCheckError();
+	
 	cudaMemcpy(h_filter_Image, d_filter_Image, NUMPIX*sizeof(float), cudaMemcpyDeviceToHost);
 	unsigned char* bin_image = getQuantile(d_filter_Image, h_filter_Image,0.985);
 	

	}
	unsigned char* h_bin_image = (unsigned char*)malloc(ROI_IMAGE_WIDTH*ROI_IMAGE_HEIGHT*sizeof(unsigned char));
	cudaMemcpy(h_bin_image, d_bin_image,ROI_IMAGE_WIDTH*ROI_IMAGE_HEIGHT*sizeof(unsigned char), cudaMemcpyDeviceToHost);
	//CudaCheckError();

	/*
	cudaEventRecord(stop);

	float bin_thresh = (max)/2;
	unsigned char* d_bin_image;
	cudaMalloc((void**)&d_bin_image, ROI_IMAGE_WIDTH*ROI_IMAGE_HEIGHT*sizeof(unsigned char));
	CudaCheckError();
	
	cudaMemset(d_bin_image, 0, ROI_IMAGE_WIDTH*ROI_IMAGE_HEIGHT*sizeof(unsigned char));
	CudaCheckError();

	dim3 gridSize_roi((ROI_IMAGE_WIDTH + blockSize.x -1)/blockSize.x, (ROI_IMAGE_HEIGHT + blockSize.y -1)/blockSize.y);

	thresh_binary<<<gridSize_roi, blockSize>>>(d_roi_selectedImage, d_bin_image,bin_thresh, 1);
	cudaDeviceSynchronize();
	CudaCheckError();

	if(debug_pre_process)
	{
