IppStatus PrintOutputImages(const Image2D &image_in, const Image2D &image_bpass, const Image2D &image_localmax, const Params &Parameters, const int framenumber, const int stacknumber, FIMULTIBITMAP *filt_imagestack, FIMULTIBITMAP *over_imagestack) { IppStatus status; Image2D image_out(image_in.get_length(), image_in.get_width()); Image2D image_overlay(image_in.get_length(), image_in.get_width()); Image2D centerpoints(image_in.get_length(), image_in.get_width()); Ipp32f brightness = 75; //scale points to brightness status = ippiMulC_32f_C1R(image_localmax.get_image2D(), image_localmax.get_stepsize(), brightness, centerpoints.get_image2D(), centerpoints.get_stepsize(), image_localmax.get_ROIfull()); //convert and save files as TIFFs status = ippiAdd_32f_C1R( image_bpass.get_image2D(), image_bpass.get_stepsize(), centerpoints.get_image2D(), centerpoints.get_stepsize(), image_out.get_image2D(), image_out.get_stepsize(), image_out.get_ROIfull()); status = ippiAdd_32f_C1R( image_in.get_image2D(), image_in.get_stepsize(), centerpoints.get_image2D(), centerpoints.get_stepsize(), image_overlay.get_image2D(), image_overlay.get_stepsize(), image_in.get_ROIfull()); status = IPP_to_TIFF(image_overlay, over_imagestack); status = IPP_to_TIFF(image_out, filt_imagestack); return status; }
// tac 2009-09-15 // IppStatus iden::BandPass_2D(Image2D &image_in, Image2D &image_bandpassed, const int feature_radius, const float hwhm_length) { /*//set status variable*/ IppStatus status; Gaussian_Kernel GaussKernel(feature_radius, hwhm_length, image_in.get_width(), image_in.get_height()); Tophat_Kernel TopHatKernel(feature_radius, image_in.get_width(), image_in.get_height()); // int number_of_pixels = image_in.get_numberofpixels(); int step_size = image_in.get_stepsize(); // trim off extreme outliers (cut top .2% of data off /*//Create and initialize intermediate images*/ Image2D image_gauss_col(image_in.get_height(), image_in.get_width()); Image2D image_gauss_rowcol(image_in.get_height(), image_in.get_width()); Image2D image_tophat(image_in.get_height(), image_in.get_width()); /*//Gaussian kernel convolution*/ status = ippiFilterColumn_32f_C1R(image_in.get_image2D() + GaussKernel.get_offset(), step_size, image_gauss_col.get_image2D() + GaussKernel.get_offset(), step_size, GaussKernel.get_ROI_size(), GaussKernel.get_gaussian_kernel(), GaussKernel.get_kernel_length(), GaussKernel.get_anchor_point()); status = ippiFilterRow_32f_C1R(image_gauss_col.get_image2D() + GaussKernel.get_offset(), step_size, image_gauss_rowcol.get_image2D() + GaussKernel.get_offset(), step_size, GaussKernel.get_ROI_size(), GaussKernel.get_gaussian_kernel(), GaussKernel.get_kernel_length(), GaussKernel.get_anchor_point()); /*//tophat kernel convolution/filterbox operation*/ status = ippiFilterBox_32f_C1R(image_in.get_image2D() + TopHatKernel.get_offset(), step_size, image_tophat.get_image2D() + TopHatKernel.get_offset(), step_size, TopHatKernel.get_ROI_size(), TopHatKernel.get_mask_size(), TopHatKernel.get_anchor_point()); /*//subtract the two images*/ status = ippiSub_32f_C1R(image_tophat.get_image2D() + TopHatKernel.get_offset(), step_size, image_gauss_rowcol.get_image2D()+TopHatKernel.get_offset(), step_size, image_bandpassed.get_image2D() + TopHatKernel.get_offset(), step_size, TopHatKernel.get_ROI_size()); /*//cutoff values below zero*/ status = ippiThreshold_LTVal_32f_C1IR(image_bandpassed.get_image2D() + TopHatKernel.get_offset(), step_size, TopHatKernel.get_ROI_size(),0,0); return status; }
IppStatus BandPass_2D(Image2D &image_in, Image2D &image_bandpassed, const int feature_radius, const int hwhm_length) { //set status variable IppStatus status; Gaussian_Kernel GaussKernel(feature_radius, hwhm_length, image_in.get_width(), image_in.get_length()); Convolution_Kernel ConvolutionKernels(feature_radius, image_in.get_width(), image_in.get_length()); Tophat_Kernel TopHatKernel(feature_radius, image_in.get_width(), image_in.get_length()); int number_of_pixels = image_in.get_numberofpixels(); int step_size = image_in.get_stepsize(); //Create and initialize intermediate images Image2D image_gauss_col(image_in.get_length(), image_in.get_width()); Image2D image_gauss_rowcol(image_in.get_length(), image_in.get_width()); Image2D image_tophat(image_in.get_length(), image_in.get_width()); //Gaussian kernel convolution status = ippiFilterColumn_32f_C1R(image_in.get_image2D() + GaussKernel.get_offset(), step_size, image_gauss_col.get_image2D() + GaussKernel.get_offset(), step_size, GaussKernel.get_ROI_size(), GaussKernel.get_gaussian_kernel(), GaussKernel.get_kernel_length(), GaussKernel.get_anchor_point()); status = ippiFilterRow_32f_C1R(image_gauss_col.get_image2D() + GaussKernel.get_offset(), step_size, image_gauss_rowcol.get_image2D() + GaussKernel.get_offset(), step_size, GaussKernel.get_ROI_size(), GaussKernel.get_gaussian_kernel(), GaussKernel.get_kernel_length(), GaussKernel.get_anchor_point()); /* //tophat kernel convolution/filterbox operation status = ippiFilterBox_32f_C1R(image_in.get_image2D() + TopHatKernel.get_offset(), step_size, image_tophat.get_image2D() + TopHatKernel.get_offset(), step_size, TopHatKernel.get_ROI_size(), TopHatKernel.get_mask_size(), TopHatKernel.get_anchor_point()); */ //change by Eli Sloutskin: take away bias of square filtering kernel status = ippiConvValid_32f_C1R(image_in.get_image2D(), step_size, image_in.get_ROIfull(), ConvolutionKernels.get_circle_kernel(), ConvolutionKernels.get_kernel_step(), ConvolutionKernels.get_kernel_size(), image_tophat.get_image2D() + ConvolutionKernels.get_offset(), step_size); ippiDivC_32f_C1IR(3*feature_radius*feature_radius, image_tophat.get_image2D(),image_tophat.get_stepsize(),image_tophat.get_ROIfull()); //subtract the two images status = ippiSub_32f_C1R(image_tophat.get_image2D() + TopHatKernel.get_offset(), step_size, image_gauss_rowcol.get_image2D()+TopHatKernel.get_offset(), step_size, image_bandpassed.get_image2D() + TopHatKernel.get_offset(), step_size, TopHatKernel.get_ROI_size()); //cutoff values below zero status = ippiThreshold_LTVal_32f_C1IR(image_bandpassed.get_image2D() + TopHatKernel.get_offset(), step_size, TopHatKernel.get_ROI_size(),0,0); return status; }
Image2D<unsigned char> Image2DGrey::down_sample() const { Image2D newImage (get_width() / 2, get_height() / 2); for (int y=0; y < newImage.get_height();y++) { int oldY = y * 2; for (int x=0; x<newImage.get_width();x++) { int oldX = x * 2; int sample1 = get_pixel(oldX, oldY); int sample2 = get_pixel(oldX + 1, oldY); int sample3 = get_pixel(oldX, oldY + 1); int sample4 = get_pixel(oldX + 1, oldY + 1); newImage.set_pixel(x,y, (sample1 + sample2 + sample3 + sample4) / 4); } } return newImage; }
IppStatus FindLocalMax_2D(Image2D &image_bpass, Image2D &image_bpass_thresh, Image2D &image_subtracted, const int intensity_threshold, const int dilation_radius) { IppStatus status; Image2D image_dilated(image_bpass.get_length(), image_bpass.get_width()); Dilation_Kernel DilationKernel(dilation_radius, image_bpass.get_width(), image_bpass.get_length()); //Threshold darker pixels in bandpassed image (in preparation for later subtraction) RecenterImage(image_bpass); status = ippiThreshold_LTVal_32f_C1R(image_bpass.get_image2D(), image_bpass.get_stepsize(), image_bpass_thresh.get_image2D(), image_bpass_thresh.get_stepsize(), image_bpass.get_ROIfull(), intensity_threshold, intensity_threshold); //Dilate Bandpassed image with a circular kernel status = ippiSet_32f_C1R(intensity_threshold, image_dilated.get_image2D(), image_dilated.get_stepsize(), image_dilated.get_ROIfull()); status = ippiDilate_32f_C1R( //image_bpass.get_image2D() + DilationKernel.get_offset(), image_bpass.get_stepsize(), image_bpass_thresh.get_image2D() + DilationKernel.get_offset(), image_bpass_thresh.get_stepsize(), image_dilated.get_image2D()+ DilationKernel.get_offset(), image_dilated.get_stepsize(), DilationKernel.get_ROI_size(), DilationKernel.get_dilation_kernel(), DilationKernel.get_mask_size(), DilationKernel.get_anchor_point()); //subtract, such that resulting array is negative to zero (for later exponentation) status = ippiSub_32f_C1R( image_dilated.get_image2D(), image_dilated.get_stepsize(), image_bpass.get_image2D(), image_bpass.get_stepsize(), image_subtracted.get_image2D(), image_subtracted.get_stepsize(), image_bpass.get_ROIfull()); //exponentiate subtracted array, then threshold status = ippiExp_32f_C1IR(image_subtracted.get_image2D(), image_subtracted.get_stepsize(), image_subtracted.get_ROIfull()); status = ippiThreshold_LTValGTVal_32f_C1IR(image_subtracted.get_image2D(), image_subtracted.get_stepsize(), image_subtracted.get_ROIfull(), 1-epsilon, 0, 1-epsilon, 1); return status; }
void Iden::process_frame(const Image2D & img_in, unsigned int frame_number, const Md_store * md_store_in, Wrapper_i_plu & wrapper_out) const { Md_store * md_store_local = new Md_store(); if (! md_store_in) md_store_local->add_elements(md_store_in); float hwhm,thresh,top_cut,a,b; int feature_rad,dilation_rad, mask_rad; unsigned int avg_count; // the parameters should be verified when, they are set, but the try // can't hurt. try { params_.get_value("threshold",thresh); params_.get_value("p_rad",feature_rad); params_.get_value("hwhm",hwhm); params_.get_value("d_rad",dilation_rad); params_.get_value("mask_rad",mask_rad); params_.get_value("top_cut",top_cut); } catch(logic_error & e) { std::cerr<<"Iden::error parsing the parameters"<<std::endl; std::cerr<<e.what()<<std::endl; throw; } unsigned int height = img_in.get_height(); unsigned int width = img_in.get_width(); // object for holding band passed image Image2D image_bpass(height,width); // object for holding the thresholded band passed image Image2D image_bpass_thresh(height,width); // object that holds the local max Image2D image_localmax(height,width); // local mutable copy of image Image2D image_in_local(img_in); RecenterImage(image_in_local); IppStatus status; status = BandPass_2D(image_in_local, image_bpass, feature_rad, hwhm); status = FindLocalMax_2D(image_bpass, image_bpass_thresh, image_localmax, thresh, dilation_rad); RecenterImage(image_bpass_thresh); // get out massive nx9 array int counter; Ipp32f (*particledata)[9] = ParticleStatistics(image_localmax, image_bpass_thresh, mask_rad, feature_rad, counter); // set data in wrapper wrapper_out.add_frame_data(particledata,frame_number,counter); // set metadata in wrapper // the wrapper takes responsibility for the object wrapper_out.set_Md_store(frame_number,md_store_local); // clean up wrapper }