From 7e1c081fdbb6fa0072af8bc1a1486540d8f3014d Mon Sep 17 00:00:00 2001 From: Dan Turner Date: Thu, 22 Aug 2019 12:11:00 -0600 Subject: [PATCH] change the way .cine files are filtered for failed pixels --- src/cine/DICe_Cine.cpp | 212 ++++++++++-------------------- src/cine/DICe_Cine.h | 65 +++------ src/core/DICe_Main.cpp | 3 - src/core/DICe_Parser.cpp | 4 +- src/utils/src/DICe_ImageIO.cpp | 20 +-- src/utils/src/DICe_ImageIO.h | 16 +-- tests/component/DICe_TestCine.cpp | 43 ++++-- tools/DICe_CineToTiff.cpp | 4 +- 8 files changed, 133 insertions(+), 234 deletions(-) diff --git a/src/cine/DICe_Cine.cpp b/src/cine/DICe_Cine.cpp index 6573d597..ec5ee45e 100644 --- a/src/cine/DICe_Cine.cpp +++ b/src/cine/DICe_Cine.cpp @@ -80,65 +80,61 @@ const static uint16_t LinLUT[1024] = 4064,4095,4095,4095,4095,4095,4095,4095,4095,4095 }; Cine_Reader::Cine_Reader(const std::string & file_name, - std::ostream * out_stream, - const bool filter_failed_pixels): + std::ostream * out_stream): out_stream_(out_stream), bit_12_warning_(false), - filter_failed_pixels_(filter_failed_pixels), - filter_value_(0.0), - conversion_factor_(0.0) + filter_threshold_(1.0E10), + conversion_factor_(1.0), + filter_initialized_(false) { cine_header_ = read_cine_headers(file_name.c_str(),out_stream); - const int64_t begin = cine_header_->image_offsets_[0]; TEUCHOS_TEST_FOR_EXCEPTION(cine_header_->header_.ImageCount<=1,std::runtime_error,"Error, cine must have at least two images"); const int64_t end = cine_header_->image_offsets_[1]; long long int buffer_size = end - begin; TEUCHOS_TEST_FOR_EXCEPTION(buffer_size<=0,std::runtime_error,"Error, invalid buffer size"); header_offset_ = (buffer_size - cine_header_->bitmap_header_.biSizeImage) / sizeof(uint8_t); - - if(cine_header_->bit_depth_==BIT_DEPTH_8){ - filter_value_ = filter_failed_pixels_ ? 250.0 : 255.0; - conversion_factor_ = filter_value_=0.0?255.0:255.0/filter_value_; - } - else if(cine_header_->bit_depth_==BIT_DEPTH_16){ - filter_value_ = filter_failed_pixels_ ? 65500.0 : 65535.0; - conversion_factor_ = filter_value_==0.0?255.0:255.0/filter_value_; - } - else if(cine_header_->bit_depth_==BIT_DEPTH_10_PACKED){ - filter_value_ = filter_failed_pixels_ ? 4090.0 : 4096.0; - conversion_factor_ = filter_value_=0.0?255.0:255.0 / filter_value_; - } - //if(filter_failed_pixels_) // use this filter to do a binning filter (turned off for now) - // initialize_cine_filter(0); // set up the filtering based on the 0th frame intensities } void -Cine_Reader::initialize_cine_filter(const int_t frame_index){ - +Cine_Reader::initialize_filter(const bool filter_failed_pixels, + const bool convert_to_8_bit, + const int_t frame_index, + const bool reinit){ + if(filter_initialized_&&!reinit) return; // get a frame with no windows const int_t w = cine_header_->bitmap_header_.biWidth; const int_t h = cine_header_->bitmap_header_.biHeight; Teuchos::ArrayRCP intensities(w*h,0.0); - get_frame(0,0,w,h,intensities.getRawPtr(),true,frame_index,false,false); - //Teuchos::RCP base_img = get_frame(frame_index,0,0,w-1,h-1,false,false); - // create a std::vector from the image intensity values - //std::vector intensities_sorted(base_img->intensities().get(),base_img->intensities().get() + base_img()->intensities().size()); + // reset the parameters in case this gets called multiple times + filter_threshold_ = 1.0E10; + conversion_factor_ = 1.0; + get_frame(0,0,w,h,intensities.getRawPtr(),true,frame_index); std::vector intensities_sorted(intensities.get(),intensities.get() + intensities.size()); - // sort the intensities + // sort the intensities lowest to highest std::sort(intensities_sorted.begin(),intensities_sorted.end()); - // create the bins - const int_t bin_size = w*h/10; - assert(bin_size>0); - const int_t bin_8_start = w*h - 2*bin_size; - const int_t bin_8_end = w*h - bin_size; - intensity_t avg_intens = 0.0; - for(int_t i=bin_8_start;i4096.0){ + conversion_factor_ = 255.0/65535.0; + } + else if(outlier_intensity>255.0){ + conversion_factor_ = 255.0/4096.0; + } + } + DEBUG_MSG("Cine_Reader::intialize_cine_filter(): filter intensity threshold: " << filter_threshold_); + DEBUG_MSG("Cine_Reader::intialize_cine_filter(): conversion factor: " << conversion_factor_); + filter_initialized_ = true; } void @@ -149,9 +145,7 @@ Cine_Reader::get_average_frame(const int_t frame_start, const int_t width, const int_t height, intensity_t * intensities, - const bool is_layout_right, - const bool filter_failed_pixels, - const bool convert_to_8_bit){ + const bool is_layout_right){ for(int_t i=0;i temp_intens(width*height,0.0); - get_frame(offset_x,offset_y,width,height,temp_intens.getRawPtr(),is_layout_right,frame,filter_failed_pixels,convert_to_8_bit); + get_frame(offset_x,offset_y,width,height,temp_intens.getRawPtr(),is_layout_right,frame); for(int_t i=0;ibit_depth_==BIT_DEPTH_8){ - get_frame_8_bit(offset_x,offset_y,width,height,intensities,is_layout_right,frame_index,filter_failed_pixels); + get_frame_8_bit(offset_x,offset_y,width,height,intensities,is_layout_right,frame_index); } else if (cine_header_->bit_depth_==BIT_DEPTH_16){ - get_frame_16_bit(offset_x,offset_y,width,height,intensities,is_layout_right,frame_index,filter_failed_pixels); - } - else if (cine_header_->bit_depth_==BIT_DEPTH_10_PACKED&&filter_failed_pixels){ - get_frame_10_bit_filtered(offset_x,offset_y,width,height,intensities,is_layout_right,frame_index); + get_frame_16_bit(offset_x,offset_y,width,height,intensities,is_layout_right,frame_index); } else if (cine_header_->bit_depth_==BIT_DEPTH_10_PACKED){ get_frame_10_bit(offset_x,offset_y,width,height,intensities,is_layout_right,frame_index); @@ -198,8 +180,6 @@ Cine_Reader::get_frame(const int_t offset_x, std::cerr << "Error, invalid bit depth" << std::endl; throw std::exception(); } - // replace the conversion factor if it was deactivated - conversion_factor_ = conversion_factor_temp; } void @@ -209,9 +189,11 @@ Cine_Reader::get_frame_8_bit(const int_t offset_x, const int_t height, intensity_t * intensities, const bool is_layout_right, - const int_t frame_index, - const bool filter_failed_pixels){ + const int_t frame_index){ DEBUG_MSG("Cine_Reader::get_frame_8_bit(): frame index: " << frame_index); + DEBUG_MSG("Cine_Reader::get_frame_8_bit(): filter threshold: " << filter_threshold_); + DEBUG_MSG("Cine_Reader::get_frame_8_bit(): conversion factor: " << conversion_factor_); + if(!is_layout_right){ std::cerr << "Error, layout left is not implemented yet" << std::endl; throw std::exception(); @@ -243,9 +225,9 @@ Cine_Reader::get_frame_8_bit(const int_t offset_x, for(int_t y=0;y= filter_value_ && !(x == offset_x && y == 0)){ + if(sub_buff_ptr_8[y*w+x] >= filter_threshold_){ failed_pixels++; - intensities[(height-y-1)*width + x-offset_x] = intensities[(height-y-1)*width+x-offset_x-1]; + intensities[(height-y-1)*width + x-offset_x] = filter_threshold_*conversion_factor_; } else intensities[(height-y-1)*width + x-offset_x] = sub_buff_ptr_8[y*w+x]*conversion_factor_; @@ -269,13 +251,15 @@ Cine_Reader::get_frame_16_bit(const int_t offset_x, const int_t height, intensity_t * intensities, const bool is_layout_right, - const int_t frame_index, - const bool filter_failed_pixels){ + const int_t frame_index){ if(!is_layout_right){ std::cerr << "Error, layout left is not implemented yet" << std::endl; throw std::exception(); } DEBUG_MSG("Cine_Reader::get_frame_16_bit(): frame index: " << frame_index); + DEBUG_MSG("Cine_Reader::get_frame_16_bit(): filter threshold: " << filter_threshold_); + DEBUG_MSG("Cine_Reader::get_frame_16_bit(): conversion factor: " << conversion_factor_); + const int_t w = cine_header_->bitmap_header_.biWidth; const int_t h = cine_header_->bitmap_header_.biHeight; const int_t end_x = offset_x + width - 1; @@ -304,9 +288,9 @@ Cine_Reader::get_frame_16_bit(const int_t offset_x, for(int_t x=offset_x;x<=end_x;++x){ pixel_intensity = sub_buff_ptr_16[y*w+x]; if(pixel_intensity > max_intens) max_intens = pixel_intensity; - if(filter_failed_pixels && pixel_intensity >= filter_value_ && !(x == offset_x && y == 0)){ + if(pixel_intensity >= filter_threshold_){ failed_pixels++; - intensities[(height-y-1)*width + x-offset_x] = intensities[(height-y-1)*width+(x-offset_x)-1]; + intensities[(height-y-1)*width + x-offset_x] = filter_threshold_*conversion_factor_; } else{ intensities[(height-y-1)*width + x-offset_x] = pixel_intensity * conversion_factor_; @@ -322,21 +306,21 @@ Cine_Reader::get_frame_16_bit(const int_t offset_x, #endif // check to make sure the image is not 12bit stored as 16bit image: // if so, scale the numbers as if 12bit - if(max_intens < 4096){ + if(max_intens < 4096 && conversion_factor_==1.0){ if(out_stream_ && !bit_12_warning_){ *out_stream_ << "*** Warning, .cine file: " << cine_header_->file_name_ << std::endl << " was detected to be 12bit depth, but stored and denoted in the header as 16bit." << std::endl << " The actual intensity value range is 0 to 4095, not 0 to 65535 as denoted in the header." << std::endl; bit_12_warning_ = true; } - if(conversion_factor_!=1.0){ - for(int_t y=0;y=(int_t)cine_header_->header_.ImageCount){ std::cerr << "Error, invalid frame index " << std::endl; throw std::exception(); @@ -384,72 +371,6 @@ Cine_Reader::get_frame_10_bit(const int_t offset_x, uint16_t intensity_16 = 0.0; uint16_t intensity_16p1 = 0.0; uint16_t two_byte = 0; - for(int_t y=0;y> (6 - (chunk_offset*2)); - // use a mask to zero out the left 6 bits - two_byte = two_byte & 0x3FF; // 16 bits with only the right 10 active; - // this next step is required because the original signal was companded from 12 bits to 10, - // now we are expanding it back to 12: - two_byte = LinLUT[two_byte]; - // save off the pixel - intensities[y*width+(x-offset_x)] = two_byte * conversion_factor_; - } - } - cine_file.close(); - delete[] sub_buffer; -} - -void -Cine_Reader::get_frame_10_bit_filtered(const int_t offset_x, - const int_t offset_y, - const int_t width, - const int_t height, - intensity_t * intensities, - const bool is_layout_right, - const int_t frame_index){ - if(!is_layout_right){ - std::cerr << "Error, layout left is not implemented yet" << std::endl; - throw std::exception(); - } - DEBUG_MSG("Cine_Reader::get_frame_10_bit_filtered(): frame index: " << frame_index); - const int_t w = cine_header_->bitmap_header_.biWidth; - assert(width<=w); - assert(height<=cine_header_->bitmap_header_.biHeight); - assert(offset_x>=0&&offset_x=0&&offset_ybitmap_header_.biHeight); - /// buffer for sub_image reading - assert(w%8==0); - const int_t sub_buffer_size = (height+1) * w * 10 / 8; - char * sub_buffer = new char[sub_buffer_size]; // + 1 to oversize the buffer - DEBUG_MSG("Cine_Reader::get_frame_10_bit_filtered(): buffer_size: " << sub_buffer_size); - DEBUG_MSG("Cine_Reader::get_frame_10_bit_filtered(): start_x " << offset_x << " end_x " << end_x << " start_y " << offset_y << " end_y " << offset_y + height - 1); - uint8_t * sub_buff_ptr_8 = reinterpret_cast(sub_buffer); - // open the file - std::ifstream cine_file(cine_header_->file_name_.c_str(), std::ios::in | std::ios::binary); - if (cine_file.fail()){ - std::cerr << "Error, can't open the file: " << cine_header_->file_name_ << std::endl; - throw std::exception(); - } - // position to the first frame in this set: - const int64_t begin_frame = cine_header_->image_offsets_[frame_index] + header_offset_ + (offset_y * w * 10 / 8); - cine_file.seekg(begin_frame); - // read the buffer - cine_file.read(sub_buffer,sub_buffer_size); - // unpack the 10 bit image data from the array - uint16_t intensity_16 = 0.0; - uint16_t intensity_16p1 = 0.0; - uint16_t two_byte = 0; int_t failed_pixels=0; for(int_t y=0;y= filter_value_ && !(x == offset_x && y == 0)){ + if(two_byte>=filter_threshold_){ failed_pixels++; - intensities[y*width+(x-offset_x)] = intensities[y*width+(x-offset_x)-1]; + intensities[y*width+(x-offset_x)] = filter_threshold_ * conversion_factor_; } else intensities[y*width+(x-offset_x)] = two_byte * conversion_factor_; diff --git a/src/cine/DICe_Cine.h b/src/cine/DICe_Cine.h index 7a712a2f..b3ab2b8d 100644 --- a/src/cine/DICe_Cine.h +++ b/src/cine/DICe_Cine.h @@ -201,10 +201,10 @@ Cine_Reader /// \brief default constructor /// \param file_name the name of the cine file /// \param out_stream (optional) output stream - /// \param filter_failed_pixels true if failed pixels should be filtered out by taking the neighbor value + /// \param filter_failed_pixels true if failed pixels should be filtered out by taking the next highest value + /// \param convert_to_8_bit true if the values should be scaled to 8 bit Cine_Reader(const std::string & file_name, - std::ostream * out_stream = NULL, - const bool filter_failed_pixels=false); + std::ostream * out_stream = NULL); /// default destructor virtual ~Cine_Reader(){}; @@ -216,17 +216,13 @@ Cine_Reader /// \param intensities the intensity array /// \param is_layout_right colum or row oriented storage flag (not used yet for cine) /// \param frame_index the frame to gather - /// \param filter_failed_pixels get rid of outlier pixels or failed pixels - /// \param convert_to_8_bit true if the values should be scaled to 8 bit void get_frame(const int_t offset_x, const int_t offset_y, const int_t width, const int_t height, intensity_t * intensities, const bool is_layout_right, - const int_t frame_index, - const bool filter_failed_pixels, - const bool convert_to_8_bit); + const int_t frame_index); /// \brief generic frame fetch with averaging across frames /// \param frame_start the initial frame to start averaging with @@ -237,8 +233,6 @@ Cine_Reader /// \param height the height of the image or subimage (intensities must be pre-allocated as a widthxheight array) /// \param intensities the intensity array /// \param is_layout_right colum or row oriented storage flag (not used yet for cine) - /// \param filter_failed_pixels get rid of outlier pixels or failed pixels - /// \param convert_to_8_bit true if the values should be scaled to 8 bit range void get_average_frame(const int_t frame_start, const int_t frame_end, const int_t offset_x, @@ -246,9 +240,7 @@ Cine_Reader const int_t width, const int_t height, intensity_t * intensities, - const bool is_layout_right, - const bool filter_failed_pixels, - const bool convert_to_8_bit); + const bool is_layout_right); /// \brief 8 bit frame fetch /// \param offset_x offset to first pixel in x @@ -258,15 +250,13 @@ Cine_Reader /// \param intensities the intensity array /// \param is_layout_right colum or row oriented storage flag (not used yet for cine) /// \param frame_index the frame to gather - /// \param filter_failed_pixels get rid of outlier pixels or failed pixels void get_frame_8_bit(const int_t offset_x, const int_t offset_y, const int_t width, const int_t height, intensity_t * intensities, const bool is_layout_right, - const int_t frame_index, - const bool filter_failed_pixels); + const int_t frame_index); /// \brief 10 bit frame fetch /// \param offset_x offset to first pixel in x @@ -284,23 +274,6 @@ Cine_Reader const bool is_layout_right, const int_t frame_index); - /// \brief 10 bit frame fetch with filtering - /// separate function to avoid if statement for each pixel (optimization) - /// \param offset_x offset to first pixel in x - /// \param offset_y offset to first pixel in y - /// \param width the width of the image or subimage - /// \param height the height of the image or subimage (intensities must be pre-allocated as a widthxheight array) - /// \param intensities the intensity array - /// \param is_layout_right colum or row oriented storage flag (not used yet for cine) - /// \param frame_index the frame to gather - void get_frame_10_bit_filtered(const int_t offset_x, - const int_t offset_y, - const int_t width, - const int_t height, - intensity_t * intensities, - const bool is_layout_right, - const int_t frame_index); - /// \brief 16 bit frame fetch /// \param offset_x offset to first pixel in x /// \param offset_y offset to first pixel in y @@ -309,22 +282,22 @@ Cine_Reader /// \param intensities the intensity array /// \param is_layout_right colum or row oriented storage flag (not used yet for cine) /// \param frame_index the frame to gather - /// \param filter_failed_pixels get rid of outlier pixels or failed pixels void get_frame_16_bit(const int_t offset_x, const int_t offset_y, const int_t width, const int_t height, intensity_t * intensities, const bool is_layout_right, - const int_t frame_index, - const bool filter_failed_pixels); + const int_t frame_index); - /// \brief bins the pixels and determines a filter value - /// The pixels are separated into 10 bins (0-9). The top bin - /// is discarded as too bright. The average of bin 8 is used as the - /// filter value. Every pixel above the filter value is replaced with - /// it's neighbor value. The filtered values are then converted to 8 bit - void initialize_cine_filter(const int_t frame_index); + /// \brief set up the filtering of failed pixels + /// \param filter_failed_pixels true if failed pixels should be filtered out by taking the next highest value + /// \param convert_to_8_bit true if the values should be scaled to 8 bit + /// \param frame index to use to set up the filtering + void initialize_filter(const bool filter_failed_pixels, + const bool convert_to_8_bit, + const int_t frame_index=0, + const bool reinit=false); /// returns the number of images in the cine file int_t num_frames()const{ @@ -349,14 +322,14 @@ Cine_Reader std::ostream * out_stream_; /// flag to prevent warnings from appearing multiple times for each frame bool bit_12_warning_; - /// flag to filter out failed pixels - bool filter_failed_pixels_; /// file offset long long int header_offset_; - /// maximum value of intensity above which the values are filtered by taking nearest neighbor - intensity_t filter_value_; + /// maximum value of intensity above which the values are filtered (the value is set to the next highest intensity value) + intensity_t filter_threshold_; /// conversion factor for converting to 8 bit depth intensity_t conversion_factor_; + /// true if the filter has already been initialized + bool filter_initialized_; }; }// end cine namespace diff --git a/src/core/DICe_Main.cpp b/src/core/DICe_Main.cpp index c47d8742..530d015d 100644 --- a/src/core/DICe_Main.cpp +++ b/src/core/DICe_Main.cpp @@ -137,14 +137,11 @@ int main(int argc, char *argv[]) { int_t image_width = 0; int_t image_height = 0; const bool is_cine = utils::image_file_type(image_files[0].c_str()) == CINE; - bool filter_failed_pixels = false; if(is_cine){ int_t s_id = 0, e_id = 0; bool is_avg = false; utils::cine_index(image_files[0].c_str(),s_id,e_id,is_avg); first_frame_id = s_id; - filter_failed_pixels = correlation_params->get(DICe::filter_failed_cine_pixels,false); - utils::Image_Reader_Cache::instance().set_filter_failed_pixels(filter_failed_pixels); } else // non-cine input { diff --git a/src/core/DICe_Parser.cpp b/src/core/DICe_Parser.cpp index a1714b27..bba3a726 100644 --- a/src/core/DICe_Parser.cpp +++ b/src/core/DICe_Parser.cpp @@ -521,7 +521,7 @@ void decipher_image_file_names(Teuchos::RCP params, std::string cine_file_name = params->get(DICe::cine_file); cine_name << params->get(DICe::image_folder) << cine_file_name; Teuchos::RCP bhs = Teuchos::rcp(new Teuchos::oblackholestream); // outputs nothing - Teuchos::RCP cine_reader = Teuchos::rcp(new DICe::cine::Cine_Reader(cine_name.str(),bhs.getRawPtr(),false)); + Teuchos::RCP cine_reader = Teuchos::rcp(new DICe::cine::Cine_Reader(cine_name.str(),bhs.getRawPtr())); // read the image data for a frame const int_t num_images = cine_reader->num_frames(); const int_t first_frame_index = cine_reader->first_image_number(); @@ -572,7 +572,7 @@ void decipher_image_file_names(Teuchos::RCP params, std::string stereo_cine_file_name = params->get(DICe::stereo_cine_file); stereo_cine_name << params->get(DICe::image_folder) << stereo_cine_file_name; Teuchos::RCP bhs = Teuchos::rcp(new Teuchos::oblackholestream); // outputs nothing - Teuchos::RCP stereo_cine_reader = Teuchos::rcp(new DICe::cine::Cine_Reader(stereo_cine_name.str(),bhs.getRawPtr(),false)); + Teuchos::RCP stereo_cine_reader = Teuchos::rcp(new DICe::cine::Cine_Reader(stereo_cine_name.str(),bhs.getRawPtr())); // strip the .cine part from the end of the cine file: std::string stereo_trimmed_cine_name = stereo_cine_name.str(); if(stereo_trimmed_cine_name.size() > ext.size() && stereo_trimmed_cine_name.substr(stereo_trimmed_cine_name.size() - ext.size()) == ".cine" ) diff --git a/src/utils/src/DICe_ImageIO.cpp b/src/utils/src/DICe_ImageIO.cpp index 076318f7..88c8d292 100644 --- a/src/utils/src/DICe_ImageIO.cpp +++ b/src/utils/src/DICe_ImageIO.cpp @@ -205,7 +205,7 @@ void read_image(const char * file_name, int_t sub_offset_y=0; bool layout_right=true; bool is_subimage=false; - bool filter_failed_pixels=false; + bool filter_failed_pixels=true; bool convert_to_8_bit=true; if(params!=Teuchos::null){ sub_w = params->get(subimage_width,0); @@ -221,9 +221,7 @@ void read_image(const char * file_name, convert_to_8_bit = params->get(convert_cine_to_8_bit,convert_to_8_bit); } DEBUG_MSG("utils::read_image(): sub_w: " << sub_w << " sub_h: " << sub_h << " offset_x: " << sub_offset_x << " offset_y: " << sub_offset_y); - DEBUG_MSG("utils::read_image(): is_layout_right: " << is_layout_right); - DEBUG_MSG("utils::read_image(): filter_failed_pixels: " << filter_failed_pixels); - DEBUG_MSG("utils::read_image(): convert_to_8_bit: " << convert_to_8_bit); + DEBUG_MSG("utils::read_image(): is_layout_right: " << layout_right); int_t width = 0; int_t height = 0; // determine the file type based on the file_name @@ -240,22 +238,24 @@ void read_image(const char * file_name, read_rawi_image(file_name,intensities,layout_right); } else if(file_type==CINE){ + DEBUG_MSG("utils::read_image(): filter_failed_pixels: " << filter_failed_pixels); + DEBUG_MSG("utils::read_image(): convert_to_8_bit: " << convert_to_8_bit); const std::string cine_file = cine_file_name(file_name); - DEBUG_MSG("read_image(): cine file name: " << cine_file); + DEBUG_MSG("utils::read_image(): cine file name: " << cine_file); int_t end_index = -1; int_t start_index =-1; bool is_avg = false; cine_index(file_name,start_index,end_index,is_avg); // get the image dimensions Teuchos::RCP reader = Image_Reader_Cache::instance().cine_reader(cine_file); + reader->initialize_filter(filter_failed_pixels,convert_to_8_bit); width = sub_w==0?reader->width():sub_w; height = sub_h==0?reader->height():sub_h; - Image_Reader_Cache::instance().set_filter_failed_pixels(filter_failed_pixels); if(is_avg){ reader->get_average_frame(start_index-reader->first_image_number(),end_index-reader->first_image_number(), - sub_offset_x,sub_offset_y,width,height,intensities,layout_right,filter_failed_pixels,convert_to_8_bit); + sub_offset_x,sub_offset_y,width,height,intensities,layout_right); }else{ - reader->get_frame(sub_offset_x,sub_offset_y,width,height,intensities,layout_right,start_index-reader->first_image_number(),filter_failed_pixels,convert_to_8_bit); + reader->get_frame(sub_offset_x,sub_offset_y,width,height,intensities,layout_right,start_index-reader->first_image_number()); } } #ifdef DICE_ENABLE_NETCDF @@ -291,7 +291,7 @@ void read_image(const char * file_name, // apply any post processing of the images as requested if(params!=Teuchos::null){ if(params->get(remove_outlier_pixels,false)){ - remove_outliers(width,height,intensities); + spread_histogram(width,height,intensities); } if(params->get(spread_intensity_histogram,false)){ spread_histogram(width,height,intensities); @@ -471,7 +471,7 @@ void write_image(const char * file_name, Teuchos::RCP Image_Reader_Cache::cine_reader(const std::string & id){ if(cine_reader_map_.find(id)==cine_reader_map_.end()){ - Teuchos::RCP cine_reader = Teuchos::rcp(new DICe::cine::Cine_Reader(id,NULL,filter_failed_pixels_)); + Teuchos::RCP cine_reader = Teuchos::rcp(new DICe::cine::Cine_Reader(id,NULL)); cine_reader_map_.insert(std::pair >(id,cine_reader)); return cine_reader; } diff --git a/src/utils/src/DICe_ImageIO.h b/src/utils/src/DICe_ImageIO.h index 92afdc97..1e3da621 100644 --- a/src/utils/src/DICe_ImageIO.h +++ b/src/utils/src/DICe_ImageIO.h @@ -202,31 +202,21 @@ class Image_Reader_Cache{ return instance_; } - /// filters failed pixels from the images - void set_filter_failed_pixels(const bool flag){ - filter_failed_pixels_ = flag; - } - - /// filters failed pixels from the images - bool filter_failed_pixels()const{ - return filter_failed_pixels_; - } - /// add a cine reader to the map /// \param id the string name of the reader in case multiple headers are loaded (for example in stereo) /// if the reader doesn't exist, it gets created Teuchos::RCP cine_reader(const std::string & id); + /// clear the map + void clear(){cine_reader_map_.clear();} private: /// constructor - Image_Reader_Cache():filter_failed_pixels_(false){}; + Image_Reader_Cache(){}; /// copy constructor Image_Reader_Cache(Image_Reader_Cache const&); /// asignment operator void operator=(Image_Reader_Cache const &); /// map of cine readers std::map > cine_reader_map_; - /// filter failed pixels from images as they are loaded - bool filter_failed_pixels_; }; diff --git a/tests/component/DICe_TestCine.cpp b/tests/component/DICe_TestCine.cpp index 80c39b62..019e7873 100644 --- a/tests/component/DICe_TestCine.cpp +++ b/tests/component/DICe_TestCine.cpp @@ -68,7 +68,6 @@ int main(int argc, char *argv[]) { *outStream << "--- Begin test ---" << std::endl; std::vector cine_files; - // the bool is whether ot not to convert the frame to 8 bit cine_files.push_back("packed_12bpp"); cine_files.push_back("packed_raw_12bpp"); cine_files.push_back("phantom_v12_raw_16bpp"); @@ -81,6 +80,10 @@ int main(int argc, char *argv[]) { cine_files.push_back("phantom_v7_raw_16bpp"); cine_files.push_back("phantom_v9_raw_16bpp"); + Teuchos::RCP params = Teuchos::rcp(new Teuchos::ParameterList()); + params->set(filter_failed_cine_pixels,false); + params->set(convert_cine_to_8_bit,true); + // all of these cine files should be dimensions 128 x 256 and have 6 frames each for(size_t i=0;i cine_img = Teuchos::rcp(new Image(markup_name.str().c_str())); + Teuchos::RCP cine_img = Teuchos::rcp(new Image(markup_name.str().c_str(),params)); std::stringstream name; //std::stringstream outname; //std::stringstream tiffname; @@ -124,8 +127,8 @@ int main(int argc, char *argv[]) { bool intensity_value_error = false; for(int_t y=0;y 0.05){ - //std::cout << x << " " << y << " actual " << (*cine_img)(x,y) << " exptected " << cine_img_exact(x,y) << std::endl; + if(std::abs((*cine_img)(x,y)-cine_img_exact(x,y)) > 0.5){ + std::cout << x << " " << y << " actual " << (*cine_img)(x,y) << " exptected " << cine_img_exact(x,y) << std::endl; intensity_value_error=true; } } @@ -169,10 +172,13 @@ int main(int argc, char *argv[]) { } *outStream << "testing reading a set of sub regions from a 10 bit cine " << std::endl; + // clear any cine image reader instances lying around + utils::Image_Reader_Cache::instance().clear(); DICe::cine::Cine_Reader cine_reader("./images/packed_12bpp.cine",outStream.getRawPtr()); std::stringstream win_frame; win_frame << "./images/packed_12bpp_" << cine_reader.first_image_number() << ".cine"; Teuchos::RCP imgParams = Teuchos::rcp(new Teuchos::ParameterList()); + imgParams->set(DICe::filter_failed_cine_pixels,false); imgParams->set(DICe::convert_cine_to_8_bit,false); Teuchos::RCP image_0_rcp = Teuchos::rcp(new Image(win_frame.str().c_str(),170,13,208-170+1,42-13+1,imgParams)); //image_0_rcp->write("motion_window_12bpp.tif"); @@ -195,7 +201,7 @@ int main(int argc, char *argv[]) { for(int_t y=0;y 0.05){ - //std::cout << x << " " << y << " actual " << (* image_rcps[i])(x,y) << " exptected " << cine_img_exact(x,y) << std::endl; + std::cout << x << " " << y << " actual " << (* image_rcps[i])(x,y) << " exptected " << cine_img_exact(x,y) << std::endl; intensity_value_error=true; } } @@ -212,7 +218,7 @@ int main(int argc, char *argv[]) { const int_t frame_5_index = 5 + cine_reader_8.first_image_number(); std::stringstream file_name_8; file_name_8 << "./images/phantom_v1610_" << frame_5_index << ".cine"; - Teuchos::RCP image_8 = Teuchos::rcp(new Image(file_name_8.str().c_str(),158,15,196-158+1,45-15+1)); + Teuchos::RCP image_8 = Teuchos::rcp(new Image(file_name_8.str().c_str(),158,15,196-158+1,45-15+1,imgParams)); //image_8->write("motion_window_8.tif"); bool intensity_value_error = false; #if DICE_USE_DOUBLE @@ -224,7 +230,7 @@ int main(int argc, char *argv[]) { for(int_t y=0;yheight();++y){ for(int_t x=0;xwidth();++x){ if(std::abs((*image_8)(x,y)-img_8_exact(x,y)) > 0.05){ - //std::cout << x << " " << y << " " << std::abs((*image_8)(x,y)-img_8_exact(x,y)) < img_cine_0 = Teuchos::rcp(new Image("./images/phantom_v1610_16bpp_-85.cine")); + Teuchos::RCP img_cine_0 = Teuchos::rcp(new Image("./images/phantom_v1610_16bpp_-85.cine",params)); Teuchos::RCP img_cine_0_gold = Teuchos::rcp(new Image("./images/image_cine_-85.rawi")); - const scalar_t diff = img_cine_0->diff(img_cine_0_gold); - *outStream << "diff cine made without manual header creation vs gold: " << diff << std::endl; - if(diff > 0.001){ - *outStream << "Error, the images do not match" << std::endl; + //const scalar_t diff = img_cine_0->diff(img_cine_0_gold); + //*outStream << "diff cine made without manual header creation vs gold: " << diff << std::endl; + //if(diff > 0.001){ + intensity_value_error = false; + for(int_t y=0;yheight();++y){ + for(int_t x=0;xwidth();++x){ + if(std::abs((*img_cine_0)(x,y)-(*img_cine_0_gold)(x,y)) > 0.5){ + intensity_value_error=true; + } + } + } + if(intensity_value_error){ + *outStream << "Error, the v1610 bit intensity values are not correct" << std::endl; errorFlag++; } +// *outStream << "Error, the images do not match" << std::endl; +// errorFlag++; + //} //img_cine_0->write("image_cine_-85.rawi"); #endif diff --git a/tools/DICe_CineToTiff.cpp b/tools/DICe_CineToTiff.cpp index f9885960..23efad7b 100644 --- a/tools/DICe_CineToTiff.cpp +++ b/tools/DICe_CineToTiff.cpp @@ -138,8 +138,8 @@ int main(int argc, char *argv[]) { // filter out failed cine pixels Teuchos::RCP params = Teuchos::rcp(new Teuchos::ParameterList()); - params->set(remove_outlier_pixels,true); - params->set(spread_intensity_histogram,true); + params->set(filter_failed_cine_pixels,true); + params->set(convert_cine_to_8_bit,true); for(int_t i=start_frame;i<=end_frame;++i){ int_t num_digits_total = 0;