def visualize_result(index): print('loss_fun_6num of this result:',loss_fun_6num(test_i[index], prediction[index])) print(test_i[index].shape) print(prediction[index].shape) print('ssim of this result:',ssim_index(test_i[index], prediction[index]).numpy()) original_image = reconstruct_img(test_i[index].numpy()) noisy_image = reconstruct_img(test_ni[index].numpy()) denoised_image = reconstruct_img(prediction[index]) print(denoised_image.shape) print(noisy_image.shape) print('loss_fun_6num and ssim, ssim_m_d, with the untreated noisy image:') print(loss_fun_6num(test_i[index], test_ni[index])) print(ssim_index(test_i[index], test_ni[index])) print(ssim_mean_diffusivity(test_i[index], test_ni[index])) k = 0 # z slice ###### Print and test original_evals = np.zeros((x_size,y_size,1,3)) original_evecs = np.zeros((x_size,y_size,1,3,3)) denoised_evals = np.zeros((x_size,y_size,1,3)) denoised_evecs = np.zeros((x_size,y_size,1,3,3)) noisy_evals = np.zeros((x_size,y_size,1,3)) noisy_evecs = np.zeros((x_size,y_size,1,3,3)) for i in range(x_size): for j in range(y_size): #print(denoised_image[i,j,k]) #print(np.linalg.eig(denoised_image[i,j,k])) # Calculate the evals/evecs and order them in descending order original_evals[i,j,k], original_evecs[i,j,k] = np.linalg.eigh(original_image[i,j,k]) original_evals[i,j,k], original_evecs[i,j,k] = np.flip(original_evals[i,j,k]), np.fliplr(original_evecs[i,j,k]) denoised_evals[i,j,k], denoised_evecs[i,j,k] = np.linalg.eigh(denoised_image[i,j,k]) denoised_evals[i,j,k], denoised_evecs[i,j,k] = np.flip(denoised_evals[i,j,k]), np.fliplr(denoised_evecs[i,j,k]) noisy_evals[i,j,k], noisy_evecs[i,j,k] = np.linalg.eigh(noisy_image[i,j,k]) noisy_evals[i,j,k], noisy_evecs[i,j,k] = np.flip(noisy_evals[i,j,k]), np.fliplr(noisy_evecs[i,j,k]) scale = (3 if (data_name == 'mris') else 1) visualize(original_evals, original_evecs, scale, 'original_ellipsoids.png', (600,600)) visualize(noisy_evals, noisy_evecs, scale, 'noisy_ellipsoids.png', (600,600)) visualize(denoised_evals, denoised_evecs, scale, 'denoised_ellipsoids.png', (600,600))
def visualize_result(): original_image = reconstruct_img(y_true) noisy_image = reconstruct_img(y_pred0) denoised_image = reconstruct_img(y_pred) # Could multiply by maxval to k = 0 # z slice ###### Print and test original_evals = np.zeros((x_size, y_size, 1, 3)) original_evecs = np.zeros((x_size, y_size, 1, 3, 3)) denoised_evals = np.zeros((x_size, y_size, 1, 3)) denoised_evecs = np.zeros((x_size, y_size, 1, 3, 3)) noisy_evals = np.zeros((x_size, y_size, 1, 3)) noisy_evecs = np.zeros((x_size, y_size, 1, 3, 3)) for i in range(x_size): for j in range(y_size): original_evals[i, j, k], original_evecs[i, j, k] = np.linalg.eigh( original_image[i, j, k]) original_evals[i, j, k], original_evecs[i, j, k] = np.flip( original_evals[i, j, k]), np.fliplr(original_evecs[i, j, k]) denoised_evals[i, j, k], denoised_evecs[i, j, k] = np.linalg.eigh( denoised_image[i, j, k]) denoised_evals[i, j, k], denoised_evecs[i, j, k] = np.flip( denoised_evals[i, j, k]), np.fliplr(denoised_evecs[i, j, k]) noisy_evals[i, j, k], noisy_evecs[i, j, k] = np.linalg.eigh(noisy_image[i, j, k]) noisy_evals[i, j, k], noisy_evecs[i, j, k] = np.flip( noisy_evals[i, j, k]), np.fliplr(noisy_evecs[i, j, k]) scale = (3 if (data_name == 'mris') else 1) visualize(original_evals, original_evecs, scale, 'original_ellipsoids_graddes.png', (600, 600)) visualize(noisy_evals, noisy_evecs, scale, 'noisy_ellipsoids_graddes.png', (600, 600)) visualize(denoised_evals, denoised_evecs, scale, 'denoised_ellipsoids_graddes.png', (600, 600))
hog_channel = "ALL" spatial_feat = True hist_feat = True hog_feat = True for img_path in test_images: t1 = time.time() img = mpimg.imread(img_path) draw_img = np.copy(img) img = img.astype(np.float32)/255 # normalize img (we trained with pngs, and now reading jpgs. print(np.min(img), np.max(img)) # make sure that image is normalized windows = hf.slide_window(img, x_start_stop=[None, None], y_start_stop=y_start_stop, xy_window=(96, 96), xy_overlap=(overlap, overlap)) hot_windows = hf.search_windows(img, windows, svc, X_scaler, color_space=color_space, spatial_size=spatial_size, hist_bins=hist_bins, orient=orient, pix_per_cell=pix_per_cell, cell_per_block=cell_per_block, hog_channel=hog_channel, spatial_feat=spatial_feat, hist_feat=hist_feat, hog_feat=hog_feat) window_img = hf.draw_boxes(draw_img, hot_windows, color=(0, 255), thick=6) images.append(window_img) titles.append("") print(time.time() - t1, "seconds to process single image search", len(windows), "windows") fig = plt.figure(figsize=(12, 12)) hf.visualize(fig, 3, 2, images, titles) plt.show() fig.savefig("output_images/04_sliding_window_search_0_75_96by96.png")
for img_path in test_images: img = mpimg.imread(img_path) for scale in scales: out_img, heat_map = hf.find_cars(img, ystart, ystop, scale, svc, X_scaler, orient, pix_per_cell, cell_per_block, cells_per_step, spatial_size, hist_bins) heatmaps_collection.append(heat_map) sum_of_heatmaps = sum(heatmaps_collection[-2:]) # sum of last X # heatmap = hf.apply_threshold(sum_of_heatmaps, threshold=2) # thresholded heat_maps average_heat_map = sum_of_heatmaps / len(heatmaps_collection) # heat_sum_average = sum(heat_maps[-2:]) / 2 # do threshold and some kind of detection (blob or cv.contours) # heatmap = hf.apply_threshold(heatmap, 1) heatmap = np.clip(average_heat_map, 0, 255) labels = label(heatmap) # draw bounding boxes on image draw_img = hf.draw_labeled_bboxes(np.copy(img), labels) out_images.append(draw_img) out_titles.append("") out_images.append(heatmap) fig = plt.figure(figsize=(12, 18)) hf.visualize(fig, 6, 2, out_images, title="") plt.show() fig.savefig("output_images/05_images_pipeline_combined_scales.png")
data_info["n_notcars"], ' non-cars') print('of size: ', data_info["image_shape"], ' and data type:', data_info["data_type"]) # Just for fun choose random car / not-car indices and plot example images car_ind = np.random.randint(0, len(cars)) notcar_ind = np.random.randint(0, len(notcars)) # Read in car / not-car images car_image = mpimg.imread(cars[car_ind]) notcar_image = mpimg.imread(notcars[notcar_ind]) images = [car_image, notcar_image] titles = ["Random Car Image", "Random Not Car Image"] # Plot the examples fig = plt.figure(figsize=(10, 5)) hf.visualize(fig, 1, 2, images, titles) plt.show() fig.savefig("output_images/00_car_notcar.png") car_ind = np.random.randint(0, len(cars)) notcar_ind = np.random.randint(0, len(notcars)) # Read in car / not-car images car_image = mpimg.imread(cars[car_ind]) notcar_image = mpimg.imread(notcars[notcar_ind]) # gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) ycrcb_car = cv2.cvtColor(car_image, cv2.COLOR_RGB2YCrCb) car_channel_1 = ycrcb_car[:, :, 0] car_channel_2 = ycrcb_car[:, :, 1]