From f964ed18094991743e2318ff9538becea3bdf172 Mon Sep 17 00:00:00 2001 From: cvachha Date: Mon, 2 May 2022 03:01:31 -0700 Subject: [PATCH] Added a loop to get the channels and tiles for each alternate image Added some loops to get the channels for the alternate images. Then this list of channels from each alternate image gets sent to the processChannel function. Over there, there is a loop to create a list of the DFTs of each of the alternate images. I also modified the function signature of processChannel and commented out the code additions in processChannel since some of it is not complete yet. --- include/hdrplus/merge.h | 1 + src/merge.cpp | 69 ++++++++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/include/hdrplus/merge.h b/include/hdrplus/merge.h index 261846b..23c5d55 100644 --- a/include/hdrplus/merge.h +++ b/include/hdrplus/merge.h @@ -103,6 +103,7 @@ class merge cv::Mat processChannel( hdrplus::burst& burst_images, \ std::vector>>>& alignments, \ cv::Mat channel_image, \ + std::vector alternate_channel_i_list,\ float lambda_shot, \ float lambda_read); diff --git a/src/merge.cpp b/src/merge.cpp index 09b154a..8e0fdc5 100644 --- a/src/merge.cpp +++ b/src/merge.cpp @@ -45,6 +45,7 @@ namespace hdrplus } } + ///// // For each channel, perform denoising and merge for (int i = 0; i < 4; ++i) { // Get channel mat @@ -56,7 +57,25 @@ namespace hdrplus //we should be getting the individual channel in the same place where we call the processChannel function with the reference channel in its arguments //possibly we could add another argument in the processChannel function which is the channel_i for the alternate image. maybe using a loop to cover all the other images - cv::Mat merged_channel = processChannel(burst_images, alignments, channel_i, lambda_shot, lambda_read); + //create list of channel_i of alternate images: + std::vector alternate_channel_i_list; + for (int j = 0; j < burst_images.num_images; j++) { + if (j != burst_images.reference_image_idx) { + + //get alternate image + cv::Mat alt_image = burst_images.bayer_images_pad[j]; + std::vector alt_img_channel = getChannels(alt_image); //get channel array from alternate image + cv::Mat alt_channel_i(alt_image.rows / 2, alt_image.cols / 2, CV_16U, alt_img_channel[i].data()); + + alternate_channel_i_list.push_back(alt_channel_i) + } + } + + ///// + + //cv::Mat merged_channel = processChannel(burst_images, alignments, channel_i, lambda_shot, lambda_read); + + cv::Mat merged_channel = processChannel(burst_images, alignments, channel_i, alternate_channel_i_list, lambda_shot, lambda_read); // cv::imwrite("merged" + std::to_string(i) + ".jpg", merged_channel); // Put channel raw data back to channels @@ -165,6 +184,7 @@ namespace hdrplus cv::Mat merge::processChannel(hdrplus::burst& burst_images, \ std::vector>>>& alignments, \ cv::Mat channel_image, \ + std::vector alternate_channel_i_list,\ float lambda_shot, \ float lambda_read) { // Get tiles of the reference image @@ -192,43 +212,50 @@ namespace hdrplus //4. temporal factor //return: merged image patches dft - /* + //tile_size = TILE_SIZE; - double temporal_factor = 8 //8 by default + /* + double temporal_factor = 8.0 //8 by default double temporal_noise_scaling = (pow(TILE_SIZE,2) * (1.0/16*2))*temporal_factor; //start calculating the merged image tiles fft - for (int i = 0;i < burst_images.num_images; i++) { - if (i != burst_images.reference_image_idx) { + + //get the tiles of the alternate image as a list + + std::vector> alternate_channel_i_tile_list; //list of alt channel tiles + std::vector> alternate_tiles_DFT_list; //list of alt channel tiles + for (auto alt_img_channel : alternate_channel_i_list) { + std::vector alt_img_channel_tile = getReferenceTiles(alt_img_channel); //get tiles from alt image + alternate_channel_i_tile_list.push_back(alt_img_channel_tile) + + std::vector alternate_tiles_DFT_list; + for (auto alt_tile : alt_img_channel_tile) { + cv::Mat alt_tile_DFT; + alt_tile.convertTo(alt_tile_DFT, CV_32F); + cv::dft(alt_tile_DFT, alt_tile_DFT, cv::DFT_SCALE | cv::DFT_COMPLEX_OUTPUT); + alternate_tiles_DFT_list.push_back(alt_tile_DFT); } + alternate_tiles_DFT_list.push_back(alternate_tiles_DFT); } - //sample of 0th image - altername_image = burst_images.bayer_images_pad[0] - - //get the tiles of the alternate image - std::vector alternate_image_tiles = getReferenceTiles(channel_image); //get the dft of the alternate image - std::vector alternate_tiles_DFT; - for (auto alt_tile : alternate_tiles_DFT) { - cv::Mat alt_tile_DFT; - alt_tile.convertTo(alt_tile_DFT, CV_32F); - cv::dft(alt_tile_DFT, alt_tile_DFT, cv::DFT_SCALE | cv::DFT_COMPLEX_OUTPUT); - alternate_tiles_DFT.push_back(alt_tile_DFT); - } + //std::vector alternate_tiles_DFT; + - std::vector tile_differences = reference_tiles_DFT - alternate_tiles_DFT; - std::vector tile_sq_asolute_diff = tile_differences; //tile_differences.real**2 + tile_differnce.imag**2; //also tile_dist + std::vector tile_differences = reference_tiles_DFT - alternate_tiles_DFT_list; + std::vector tile_sq_asolute_diff = tile_differences; //squared absolute difference is tile_differences.real**2 + tile_differnce.imag**2; //also tile_dist + + //find the squared absolute difference across all the tiles std::vector A = tile_sq_asolute_diff/(tile_sq_asolute_diff+noise_variance) - std::vector merged_image_tiles_fft = alternate_tiles_DFT + A * tile_differences; + std::vector merged_image_tiles_fft = alternate_tiles_DFT_list + A * tile_differences; //use merged_image_tiles_fft into part 4.3 @@ -258,9 +285,9 @@ namespace hdrplus //apply the cosineWindow2D over the merged_channel_tiles_spatial and reconstruct the image + */ - // 4.4 Cosine Window Merging // Process tiles through 2D cosine window std::vector windowed_tiles;