Commit f6006466 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Adding channels to overlapped textures

parent 7780b796
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -135,10 +135,11 @@ public class CLTParameters {
	public double     diff_threshold =    1.5;   // RMS difference from average to discard channel (~ 1.0 - 1/255 full scale image)
	public boolean    diff_gauss =        true;  // when averaging images, use Gaussian around average as weight (false - sharp all/nothing)
	public double     min_agree =         3.0;   // minimal number of channels to agree on a point (real number to work with fuzzy averages)
	public boolean    dust_remove =       true;  // Do not reduce average weight when only one image differes much from the average
	public boolean    dust_remove =       true;  // Do not reduce average weight when only one image differs much from the average

	public boolean    black_back =        true;  // use Black for backdrop outside of the FOV
	public boolean    keep_weights =      true;  // add port weights to RGBA stack (debug feature)
	public boolean    replace_weights =   false; //replace port weights with ports textures (16x16)
	public boolean    sharp_alpha =       false; // combining mode for alpha channel: false - treat as RGB, true - apply center 8x8 only
	public double     alpha0 = 	          0.6; // > .525 Alpha channel 0.0 threshold (lower - transparent) (watch for far objects)
	public double     alpha1 = 	          0.8; // Alpha channel 1.0 threshold (higher - opaque) (watch for window dust)
@@ -1195,6 +1196,7 @@ public class CLTParameters {
		properties.setProperty(prefix+"dust_remove",                this.dust_remove+"");
		properties.setProperty(prefix+"black_back",                 this.black_back+"");
		properties.setProperty(prefix+"keep_weights",               this.keep_weights+"");
		properties.setProperty(prefix+"replace_weights",            this.replace_weights+"");
		properties.setProperty(prefix+"sharp_alpha",                this.sharp_alpha+"");

		properties.setProperty(prefix+"alpha0",                     this.alpha0 +"");
@@ -2095,6 +2097,7 @@ public class CLTParameters {
		if (properties.getProperty(prefix+"dust_remove")!=null)                   this.dust_remove=Boolean.parseBoolean(properties.getProperty(prefix+"dust_remove"));
		if (properties.getProperty(prefix+"black_back")!=null)                    this.black_back=Boolean.parseBoolean(properties.getProperty(prefix+"black_back"));
		if (properties.getProperty(prefix+"keep_weights")!=null)                  this.keep_weights=Boolean.parseBoolean(properties.getProperty(prefix+"keep_weights"));
		if (properties.getProperty(prefix+"replace_weights")!=null)               this.replace_weights=Boolean.parseBoolean(properties.getProperty(prefix+"replace_weights"));
		if (properties.getProperty(prefix+"sharp_alpha")!=null)                   this.sharp_alpha=Boolean.parseBoolean(properties.getProperty(prefix+"sharp_alpha"));
		if (properties.getProperty(prefix+"alpha0")!=null)                        this.alpha0=Double.parseDouble(properties.getProperty(prefix+"alpha0"));
		if (properties.getProperty(prefix+"alpha1")!=null)                        this.alpha1=Double.parseDouble(properties.getProperty(prefix+"alpha1"));
@@ -3033,6 +3036,7 @@ public class CLTParameters {
		gd.addCheckbox    ("Do not reduce average weight when only one image differes much from the average",           this.dust_remove);
		gd.addCheckbox    ("Use black for backdrop outside of the FOV",                                         this.black_back);
		gd.addCheckbox    ("Add port weights to RGBA stack (debug feature)",                                    this.keep_weights);
		gd.addCheckbox    ("Replace port weights with per-channel MIDCT (16x16) - were relevant",               this.replace_weights);
		gd.addCheckbox    ("Alpha channel: use center 8x8 (unchecked - treat same as RGB)",                     this.sharp_alpha);
		gd.addNumericField("Alpha channel 0.0 thereshold (lower - transparent)",                                this.alpha0,   3);
		gd.addNumericField("Alpha channel 1.0 threshold (higher - opaque)",                                     this.alpha1,   3);
@@ -4238,6 +4242,7 @@ public class CLTParameters {
		this.dust_remove=           gd.getNextBoolean();
		this.black_back=            gd.getNextBoolean();
		this.keep_weights=          gd.getNextBoolean();
		this.replace_weights=       gd.getNextBoolean();
		this.sharp_alpha=           gd.getNextBoolean();
		this.alpha0=                gd.getNextNumber();
		this.alpha1=                gd.getNextNumber();
+32 −14
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ public class GpuQuad{ // quad camera description
	
	
	
	int host_get_textures_shared_size( // in bytes
	static int host_get_textures_shared_size( // in bytes
			//__device__ int get_textures_shared_size( // in bytes
			int                num_cams,     // actual number of cameras
			int                num_colors,   // actual number of colors: 3 for RGB, 1 for LWIR/mono
@@ -440,7 +440,8 @@ public class GpuQuad{ // quad camera description
		texture_stride = (int)(device_stride[0] / Sizeof.FLOAT);
		int max_rgba_width  =  (tilesX + 1) * GPUTileProcessor.DTT_SIZE;
		int max_rgba_height =  (tilesY + 1) * GPUTileProcessor.DTT_SIZE;
		int max_rbga_slices =  num_colors + 1;
//		int max_rbga_slices =  num_colors + 1; // num_cams
		int max_rbga_slices =  num_colors + 1 + (num_colors * num_cams); // colors, alpha, colors per channel
		cuMemAllocPitch (
				gpu_textures_rgba,                     // CUdeviceptr dptr,
				device_stride,                         // long[] pPitch,
@@ -2046,7 +2047,8 @@ public class GpuQuad{ // quad camera description
			double    diff_sigma,         // pixel value/pixel change
			double    diff_threshold,     // pixel value/pixel change
			double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
			boolean   dust_remove) {
			boolean   dust_remove,
			int       keep_weights) {
		if (GPUTileProcessor.USE_DS_DP) {
			execRBGA_DP(
					color_weights,  // double [] color_weights,
@@ -2056,7 +2058,8 @@ public class GpuQuad{ // quad camera description
					diff_sigma,     // double    diff_sigma,         // pixel value/pixel change
					diff_threshold, // double    diff_threshold,     // pixel value/pixel change
					min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
					dust_remove);   // boolean   dust_remove);
					dust_remove,    // boolean   dust_remove);
					keep_weights);  // int       keep_weights)					
		} else {
			execRBGA_noDP(
					color_weights,  // double [] color_weights,
@@ -2066,7 +2069,8 @@ public class GpuQuad{ // quad camera description
					diff_sigma,     // double    diff_sigma,         // pixel value/pixel change
					diff_threshold, // double    diff_threshold,     // pixel value/pixel change
					min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
					dust_remove);   // boolean   dust_remove);
					dust_remove,    // boolean   dust_remove);
					keep_weights);  // int       keep_weights)					
		}
	}
	/**
@@ -2079,6 +2083,8 @@ public class GpuQuad{ // quad camera description
	 * @param diff_threshold - never used?
	 * @param min_agree  minimal number of channels to agree on a point (real number to work with fuzzy averages
	 * @param dust_remove do not reduce average weight when only one image differs much from the average
	 * @param keep_weights (since 11/13/2022). Now 2 separate bits: +1 - generate channel weights and combo metrics.
	 *                     +2 replace port_weights with raw per-channel  (+1 is not used here for overlapping) 
	 */
	public void execRBGA_DP(
			double [] color_weights,
@@ -2088,7 +2094,8 @@ public class GpuQuad{ // quad camera description
			double    diff_sigma,         // pixel value/pixel change
			double    diff_threshold,     // pixel value/pixel change
			double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
			boolean   dust_remove) {
			boolean   dust_remove,
			int       keep_weights) {
		execCalcReverseDistortions(); // will check if it is needed first
		if (this.gpuTileProcessor.GPU_RBGA_kernel == null) {
			IJ.showMessage("Error", "No GPU kernel: GPU_TEXTURES_kernel");
@@ -2139,7 +2146,7 @@ public class GpuQuad{ // quad camera description
				Pointer.to(gpu_generate_RBGA_params),            // float             generate_RBGA_params[5],
				Pointer.to(gpu_color_weights),                   // float             weights[3],         // scale for R,B,G
				Pointer.to(new int[]   { idust_remove }),        // int               dust_remove,        // Do not reduce average weight when only one image differes much from the average
				Pointer.to(new int[]   {0}),                     // int               keep_weights,       // return channel weights after A in RGBA
				Pointer.to(new int[]   {keep_weights}),          // int               keep_weights,       // return channel weights after A in RGBA
				Pointer.to(new int[]   { texture_stride_rgba }), // const size_t      texture_rbga_stride,     // in floats
				Pointer.to(gpu_textures_rgba));                  // float           * gpu_texture_tiles)    // (number of colors +1 + ?)*16*16 rgba texture tiles

@@ -2165,6 +2172,8 @@ public class GpuQuad{ // quad camera description
	 * @param diff_threshold - never used?
	 * @param min_agree  minimal number of channels to agree on a point (real number to work with fuzzy averages
	 * @param dust_remove do not reduce average weight when only one image differs much from the average
	 * @param keep_weights (since 11/13/2022). Now 2 separate bits: +1 - generate channel weights and combo metrics.
	 *                     +2 replace port_weights with raw per-channel  (+1 is not used here for overlapping) 
	 */
	
	public void execRBGA_noDP(
@@ -2175,7 +2184,8 @@ public class GpuQuad{ // quad camera description
			double    diff_sigma,         // pixel value/pixel change
			double    diff_threshold,     // pixel value/pixel change
			double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
			boolean   dust_remove) {
			boolean   dust_remove,
			int       keep_weights) {
		execCalcReverseDistortions(); // will check if it is needed first
		if (    (this.gpuTileProcessor.GPU_CLEAR_TEXTURE_LIST_kernel == null) &&
				(this.gpuTileProcessor.GPU_MARK_TEXTURE_LIST_kernel == null) &&
@@ -2478,7 +2488,7 @@ public class GpuQuad{ // quad camera description
						Pointer.to(new float[] {(float) min_agree}),     // float       min_agree,      // minimal number of channels to agree on a point (real number to work with fuzzy averages)
						Pointer.to(gpu_color_weights),                   // float       weights[3],     // scale for R,B,G (or {1.0,0.0,0.0}
						Pointer.to(new int[]   {idust_remove}),          // int         dust_remove,        // Do not reduce average weight when only one image differes much from the average
						Pointer.to(new int[]   {0}),                     // int         keep_weights,       // return channel weights after A in RGBA
						Pointer.to(new int[]   {keep_weights}),           // int         keep_weights,       // return channel weights after A in RGBA
						// combining both non-overlap and overlap (each calculated if pointer is not null )
						Pointer.to(new int[]   { texture_stride_rgba }), // const size_t      texture_rbga_stride,     // in floats
						Pointer.to(gpu_textures_rgba),                   // float           * gpu_texture_tiles)    // (number of colors +1 + ?)*16*16 rgba texture tiles
@@ -2512,6 +2522,8 @@ public class GpuQuad{ // quad camera description
	 * @param diff_threshold - never used?
	 * @param min_agree  minimal number of channels to agree on a point (real number to work with fuzzy averages
	 * @param dust_remove do not reduce average weight when only one image differs much from the average
	 * @param keep_weights (since 11/13/2022). Now 2 separate bits: +1 - generate channel weights and combo metrics.
	 *                     +2 replace port_weights with raw per-channel   
	 * @param calc_textures calculate textures (false for macro-only output)
	 * @param calc_extra calculate extra output - low-res for macro
	 */
@@ -2524,6 +2536,7 @@ public class GpuQuad{ // quad camera description
			double    diff_threshold,     // pixel value/pixel change
			double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
			boolean   dust_remove,        // Do not reduce average weight when only one image differs much from the average
			int       keep_weights,       // 2 bits now, move to parameters
			boolean   calc_textures,
			boolean   calc_extra,
			boolean   linescan_order
@@ -2538,6 +2551,7 @@ public class GpuQuad{ // quad camera description
					diff_threshold,     // pixel value/pixel change
					min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
					dust_remove,        // Do not reduce average weight when only one image differs much from the average
					keep_weights,       // int       keep_weights,       // 2 bits now, move to parameters
					calc_textures,
					calc_extra,
					linescan_order);
@@ -2551,6 +2565,7 @@ public class GpuQuad{ // quad camera description
					diff_threshold,     // pixel value/pixel change
					min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
					dust_remove,        // Do not reduce average weight when only one image differs much from the average
					keep_weights,       // int       keep_weights,       // 2 bits now, move to parameters
					calc_textures,
					calc_extra,
					linescan_order);
@@ -2566,6 +2581,7 @@ public class GpuQuad{ // quad camera description
			double    diff_threshold,     // pixel value/pixel change
			double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
			boolean   dust_remove,        // Do not reduce average weight when only one image differs much from the average
			int       keep_weights,       // 2 bits now, move to parameters
			boolean   calc_textures,
			boolean   calc_extra,
			boolean   linescan_order)
@@ -2597,7 +2613,7 @@ public class GpuQuad{ // quad camera description
		int iis_lwir =      (is_lwir)? 1:0;
		int ilinescan_order = linescan_order? 1 : 0;
		int idust_remove =  (dust_remove)? 1 : 0;

//		int keep_weights = 0;     // 2 bits now, move to parameters
		int [] GridFullWarps =    {1, 1, 1};
		int [] ThreadsFullWarps = {1, 1, 1};

@@ -2618,6 +2634,7 @@ public class GpuQuad{ // quad camera description
				Pointer.to(gpu_generate_RBGA_params),            // float             generate_RBGA_params[5],
				Pointer.to(gpu_color_weights),                   // float             weights[3],         // scale for R,B,G
				Pointer.to(new int[] { idust_remove }),
				Pointer.to(new int[] { keep_weights }),          // +1 : "keep_weights", +2 - replace port_weights with channel output				
				Pointer.to(new int[] {calc_textures? texture_stride : 0}),
				Pointer.to(gpu_textures),
				Pointer.to(new int[]   {ilinescan_order}),       // 1, // int               linescan_order,     // if !=0 then output gpu_diff_rgb_combo in linescan order, else  - in gpu_texture_indices order
@@ -2642,6 +2659,7 @@ public class GpuQuad{ // quad camera description
			double    diff_threshold,     // pixel value/pixel change
			double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
			boolean   dust_remove,        // Do not reduce average weight when only one image differs much from the average
			int       keep_weights,       // 2 bits now, move to parameters
			boolean   calc_textures,
			boolean   calc_extra,
			boolean   linescan_order)
@@ -2656,7 +2674,7 @@ public class GpuQuad{ // quad camera description
			IJ.showMessage("Error", "No GPU kernel(s)");
			return;
		}
		int keep_texture_weights = 0; // pass as parameter?
		int keep_texture_weights = keep_weights; // pass as parameter?
		int tilesX =  img_width / GPUTileProcessor.DTT_SIZE;
		int num_colors = is_lwir? 1 : color_weights.length;
		if (num_colors > 3) num_colors = 3;
@@ -3364,7 +3382,7 @@ public class GpuQuad{ // quad camera description
		return textures;
	}

	public double [][][][] doubleTextures(
	public static double [][][][] doubleTextures( // not used
			Rectangle    woi,
			int []       indices,
			float [][][] ftextures,
@@ -3390,7 +3408,7 @@ public class GpuQuad{ // quad camera description
		return textures;
	}

	public double [][][][] doubleTextures( // may be accelerated with multithreading if needed.
	public static double [][][][] doubleTextures( // may be accelerated with multithreading if needed.
			Rectangle    woi, // null or width and height match texture_tiles
			double [][][][] texture_tiles, // null or [tilesY][tilesX]
			int []       indices,
+12 −6
Original line number Diff line number Diff line
@@ -356,7 +356,8 @@ public class ImageDtt extends ImageDttCPU {
					diff_sigma,     // double    diff_sigma,         // pixel value/pixel change
					diff_threshold, // double    diff_threshold,     // pixel value/pixel change
					min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
					dust_remove);   // boolean   dust_remove,
					dust_remove,    // boolean   dust_remove,
					0);             // int       keep_weights)
			float [][] rbga = gpuQuad.getRBGA(
					(isMonochrome() ? 1 : 3), // int     num_colors,
					(texture_woi_pix != null)? texture_woi_pix : woi);
@@ -376,6 +377,7 @@ public class ImageDtt extends ImageDttCPU {
				diff_threshold, // double    diff_threshold,     // pixel value/pixel change - never used in GPU ?
				min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
				dust_remove,    // boolean   dust_remove,        // Do not reduce average weight when only one image differs much from the average
				0,              // int       keep_weights,       // 2 bits now, move to parameters
				false,          // boolean   calc_textures,
				true,           // boolean   calc_extra
				false);         // boolean   linescan_order) // TODO: use true to avoid reordering of the low-res output 
@@ -427,6 +429,7 @@ public class ImageDtt extends ImageDttCPU {
				diff_threshold, // double    diff_threshold,     // pixel value/pixel change - never used in GPU ?
				min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
				dust_remove,    // boolean   dust_remove,        // Do not reduce average weight when only one image differs much from the average
				0,              // int       keep_weights,       // 2 bits now, move to parameters
				true,           // boolean   calc_textures,
				false,          // boolean   calc_extra
				false);         // boolean   linescan_order) 
@@ -438,7 +441,7 @@ public class ImageDtt extends ImageDttCPU {
					numcol,    // int     num_colors,
		    		false);    // clt_parameters.keep_weights); // boolean keep_weights);

			gpuQuad.doubleTextures(
			GpuQuad.doubleTextures(
		    		new Rectangle(0, 0, tilesX, tilesY), // Rectangle    woi,
		    		texture_tiles,                       // double [][][][] texture_tiles, // null or [tilesY][tilesX]
		    		texture_indices,                     // int []       indices,
@@ -663,7 +666,8 @@ public class ImageDtt extends ImageDttCPU {
				double    diff_sigma,         // pixel value/pixel change Used much larger sigma = 10.0 instead of 1.5
				double    diff_threshold,     // pixel value/pixel change
				double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
				boolean   dust_remove
				boolean   dust_remove,
				int       keep_weights       // 2 bits now, move to parameters
			){
		int numcol = isMonochrome()? 1 : 3;
		double [] col_weights = new double[numcol];
@@ -684,6 +688,7 @@ public class ImageDtt extends ImageDttCPU {
				diff_threshold, // double    diff_threshold,     // pixel value/pixel change
				min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
				dust_remove,    // boolean   dust_remove,
				keep_weights,   // int       keep_weights,       // 2 bits now, move to parameters
				true,           // boolean   calc_textures,
				false,          // boolean   calc_extra
				false);         // boolean   linescan_order)
@@ -696,7 +701,7 @@ public class ImageDtt extends ImageDttCPU {
		int tilesX = gpuQuad.img_width / GPUTileProcessor.DTT_SIZE;
		int tilesY = gpuQuad.img_height / GPUTileProcessor.DTT_SIZE;
		double [][][][] texture_tiles = new double [tilesY][tilesX][][];
		gpuQuad.doubleTextures(
		GpuQuad.doubleTextures(
	    		new Rectangle(0, 0, tilesX, tilesY), // Rectangle    woi,
	    		texture_tiles,                       // double [][][][] texture_tiles, // null or [tilesY][tilesX]
	    		texture_indices,                     // int []       indices,
@@ -744,6 +749,7 @@ public class ImageDtt extends ImageDttCPU {
				diff_threshold, // double    diff_threshold,     // pixel value/pixel change
				min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
				dust_remove,    // boolean   dust_remove,
				0,              // int       keep_weights,       // 2 bits now, move to parameters
				false,          // boolean   calc_textures,
				true,           // boolean   calc_extra
				false);         // boolean   linescan_order)
+54 −12

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -13730,7 +13730,8 @@ public class QuadCLTCPU {
						  clt_parameters.diff_sigma,     // double    diff_sigma,         // pixel value/pixel change Used much larger sigma = 10.0 instead of 1.5
						  clt_parameters.diff_threshold, // double    diff_threshold,     // pixel value/pixel change
						  clt_parameters.min_agree,      // double    min_agree,          // minimal number of channels to agree on a point (real number to work with fuzzy averages)
						  clt_parameters.dust_remove);   // boolean   dust_remove
						  clt_parameters.dust_remove,    // boolean   dust_remove
						  0);                            // int       keep_weights       // 2 bits now, move to parameters
			  }
			  if (save_diff || save_lowres) {
				  image_dtt.get_diffs_lowres( // CUDA_ERROR_INVALID_VALUE (because no tiles)
Loading