Loading src/main/java/com/elphel/imagej/readers/ImagejJp4Tiff.java +130 −2 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Iterator; import java.util.Properties; import java.util.Properties; import java.util.Set; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory; Loading @@ -60,6 +61,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXException; import com.elphel.imagej.common.ShowDoubleFloatArrays; import com.elphel.imagej.common.ShowDoubleFloatArrays; import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.TileNeibs; import com.elphel.imagej.tileprocessor.TileNeibs; import ij.ImagePlus; import ij.ImagePlus; Loading Loading @@ -96,6 +98,11 @@ public class ImagejJp4Tiff { private static final int FIXCH6_EXPECTED = 21319; // expected value private static final int FIXCH6_EXPECTED = 21319; // expected value private static final String FIXCH6_EARLIEST = "2021-12-01 00:00:00.000"; private static final String FIXCH6_EARLIEST = "2021-12-01 00:00:00.000"; private static final String FIXCH6_LATEST = "2024-12-01 00:00:00.000"; private static final String FIXCH6_LATEST = "2024-12-01 00:00:00.000"; private static final String FIXCH5_SERIAL = "00:0E:64:10:C4:35"; // private static final String FIXCH5_EARLIEST = "2023-11-02 00:00:00.000"; private static final String FIXCH5_EARLIEST = "2023-10-01 00:00:00.000"; private static final String FIXCH5_LATEST = "2024-12-01 00:00:00.000"; private static final int FIXCH5_CHANNEL = 1; // -- Fields -- // -- Fields -- Loading Loading @@ -252,7 +259,12 @@ public class ImagejJp4Tiff { int fixed_center = fix000E6410C435( int fixed_center = fix000E6410C435( meta_hash, // Hashtable<String, Object> meta_hash, meta_hash, // Hashtable<String, Object> meta_hash, pixels); // short [] pixels) pixels); // short [] pixels) int fixed_chn5=0; if (fixed_center < 0) { fixed_chn5 = fix000E6410C435_ch5( meta_hash, // Hashtable<String, Object> meta_hash, pixels); // short [] pixels) } boolean degamma = bytes_per_pixel < 2; // both JP4 and 8-bit tiff boolean degamma = bytes_per_pixel < 2; // both JP4 and 8-bit tiff Loading Loading @@ -336,6 +348,9 @@ public class ImagejJp4Tiff { if (fixed_center > 0) { if (fixed_center > 0) { imp.setProperty("FIXED_CHN6", ""+fixed_center); imp.setProperty("FIXED_CHN6", ""+fixed_center); } } if (fixed_chn5 > 0) { imp.setProperty("FIXED_CHN5", ""+fixed_chn5); } encodeProperiesToInfo(imp); encodeProperiesToInfo(imp); Location.mapFile(content_fileName, null); Location.mapFile(content_fileName, null); return imp; return imp; Loading Loading @@ -530,6 +545,119 @@ public class ImagejJp4Tiff { return true; return true; } } public static boolean needsFix000E6410C435_ch5(ImagePlus imp) { String prefix = "STD_"; String serial = (String) imp.getProperty(prefix+"Serial_Number"); if ((serial == null) || !serial.equals(FIXCH5_SERIAL)) { return false; // wrong camera } String schannel = ((String) imp.getProperty(prefix+"PageNumber")).substring(0,1); if ((schannel == null) || (Integer.parseInt(schannel) != FIXCH5_CHANNEL)) { return false; // wrong channel } String sfdate = (String) imp.getProperty(prefix+"DateTime"); sfdate = sfdate.replaceFirst(":", "-"); sfdate = sfdate.replaceFirst(":", "-")+".000"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); try { Date startDate = dateFormat.parse(FIXCH5_EARLIEST); Date endDate = dateFormat.parse(FIXCH5_LATEST); Date fileDate = dateFormat.parse(sfdate); if (fileDate.before(startDate) || fileDate.after(endDate)) { return false; // too early or too late } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } public int fix000E6410C435_ch5( Hashtable<String, Object> meta_hash, final float [] pixels) { final float [] pixels_in = pixels.clone(); final int width = reader.getSizeX(); final int height = reader.getSizeY(); final int dbg_pix = -(190+189*width); String serial = (String) meta_hash.get("Serial_Number"); if ((serial == null) || !serial.equals(FIXCH5_SERIAL)) { return -1; // wrong camera } String schannel = ((String) meta_hash.get("PageNumber")).substring(0,1); if ((schannel == null) || (Integer.parseInt(schannel) != FIXCH5_CHANNEL)) { return -2; // wrong channel } String sfdate = (String) meta_hash.get("DateTime"); sfdate = sfdate.replaceFirst(":", "-"); sfdate = sfdate.replaceFirst(":", "-")+".000"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); try { Date startDate = dateFormat.parse(FIXCH5_EARLIEST); Date endDate = dateFormat.parse(FIXCH5_LATEST); Date fileDate = dateFormat.parse(sfdate); if (fileDate.before(startDate) || fileDate.after(endDate)) { return -3; // too early or too late } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } final int [] patts = {0x060, 0x0e0}; // final int [] masks = {0x7e0, 0x7c0}; final int [] masks = {0x7c0, 0x780}; final int [] offs = {0x080, 0x100}; final TileNeibs tn = new TileNeibs(width,height); // int [] clusters = new int [width*height]; final Thread[] threads = ImageDtt.newThreadArray(ImageDtt.THREADS_MAX); final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ancorr = new AtomicInteger(0); for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { for (int ipix = ai.getAndIncrement(); ipix < pixels_in.length; ipix = ai.getAndIncrement()) { if (ipix == dbg_pix) { System.out.println("ipix==dbg_pix=="+ipix); } double dd = pixels_in[ipix]; int id = (int) dd; int mode = -1; for (int i = 0; i < patts.length; i++) { if (((id ^ patts[i]) & masks[i]) == 0) { mode = i; break; } } if (mode >= 0) { // int px = ipix % width; // int py = ipix / width; int npix = 0; double sd = 0; for (int dir = 0; dir < TileNeibs.DIRS; dir++) { int ipix1 = tn.getNeibIndex(ipix, dir); if (ipix1 >= 0) { sd+= pixels_in[ipix1]; npix++; } } if (npix > 0) { // always sd /= npix; if ((sd - dd) > (offs[mode]/2)) { pixels[ipix] += offs[mode]; ancorr.getAndIncrement(); } } } } } }; } ImageDtt.startAndJoin(threads); return ancorr.get(); // number of corrected pixels } // fixing "00:0E:64:10:C4:35" camera // fixing "00:0E:64:10:C4:35" camera public int fix000E6410C435( public int fix000E6410C435( Loading Loading
src/main/java/com/elphel/imagej/readers/ImagejJp4Tiff.java +130 −2 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Iterator; import java.util.Properties; import java.util.Properties; import java.util.Set; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory; Loading @@ -60,6 +61,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXException; import com.elphel.imagej.common.ShowDoubleFloatArrays; import com.elphel.imagej.common.ShowDoubleFloatArrays; import com.elphel.imagej.tileprocessor.ImageDtt; import com.elphel.imagej.tileprocessor.TileNeibs; import com.elphel.imagej.tileprocessor.TileNeibs; import ij.ImagePlus; import ij.ImagePlus; Loading Loading @@ -96,6 +98,11 @@ public class ImagejJp4Tiff { private static final int FIXCH6_EXPECTED = 21319; // expected value private static final int FIXCH6_EXPECTED = 21319; // expected value private static final String FIXCH6_EARLIEST = "2021-12-01 00:00:00.000"; private static final String FIXCH6_EARLIEST = "2021-12-01 00:00:00.000"; private static final String FIXCH6_LATEST = "2024-12-01 00:00:00.000"; private static final String FIXCH6_LATEST = "2024-12-01 00:00:00.000"; private static final String FIXCH5_SERIAL = "00:0E:64:10:C4:35"; // private static final String FIXCH5_EARLIEST = "2023-11-02 00:00:00.000"; private static final String FIXCH5_EARLIEST = "2023-10-01 00:00:00.000"; private static final String FIXCH5_LATEST = "2024-12-01 00:00:00.000"; private static final int FIXCH5_CHANNEL = 1; // -- Fields -- // -- Fields -- Loading Loading @@ -252,7 +259,12 @@ public class ImagejJp4Tiff { int fixed_center = fix000E6410C435( int fixed_center = fix000E6410C435( meta_hash, // Hashtable<String, Object> meta_hash, meta_hash, // Hashtable<String, Object> meta_hash, pixels); // short [] pixels) pixels); // short [] pixels) int fixed_chn5=0; if (fixed_center < 0) { fixed_chn5 = fix000E6410C435_ch5( meta_hash, // Hashtable<String, Object> meta_hash, pixels); // short [] pixels) } boolean degamma = bytes_per_pixel < 2; // both JP4 and 8-bit tiff boolean degamma = bytes_per_pixel < 2; // both JP4 and 8-bit tiff Loading Loading @@ -336,6 +348,9 @@ public class ImagejJp4Tiff { if (fixed_center > 0) { if (fixed_center > 0) { imp.setProperty("FIXED_CHN6", ""+fixed_center); imp.setProperty("FIXED_CHN6", ""+fixed_center); } } if (fixed_chn5 > 0) { imp.setProperty("FIXED_CHN5", ""+fixed_chn5); } encodeProperiesToInfo(imp); encodeProperiesToInfo(imp); Location.mapFile(content_fileName, null); Location.mapFile(content_fileName, null); return imp; return imp; Loading Loading @@ -530,6 +545,119 @@ public class ImagejJp4Tiff { return true; return true; } } public static boolean needsFix000E6410C435_ch5(ImagePlus imp) { String prefix = "STD_"; String serial = (String) imp.getProperty(prefix+"Serial_Number"); if ((serial == null) || !serial.equals(FIXCH5_SERIAL)) { return false; // wrong camera } String schannel = ((String) imp.getProperty(prefix+"PageNumber")).substring(0,1); if ((schannel == null) || (Integer.parseInt(schannel) != FIXCH5_CHANNEL)) { return false; // wrong channel } String sfdate = (String) imp.getProperty(prefix+"DateTime"); sfdate = sfdate.replaceFirst(":", "-"); sfdate = sfdate.replaceFirst(":", "-")+".000"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); try { Date startDate = dateFormat.parse(FIXCH5_EARLIEST); Date endDate = dateFormat.parse(FIXCH5_LATEST); Date fileDate = dateFormat.parse(sfdate); if (fileDate.before(startDate) || fileDate.after(endDate)) { return false; // too early or too late } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } public int fix000E6410C435_ch5( Hashtable<String, Object> meta_hash, final float [] pixels) { final float [] pixels_in = pixels.clone(); final int width = reader.getSizeX(); final int height = reader.getSizeY(); final int dbg_pix = -(190+189*width); String serial = (String) meta_hash.get("Serial_Number"); if ((serial == null) || !serial.equals(FIXCH5_SERIAL)) { return -1; // wrong camera } String schannel = ((String) meta_hash.get("PageNumber")).substring(0,1); if ((schannel == null) || (Integer.parseInt(schannel) != FIXCH5_CHANNEL)) { return -2; // wrong channel } String sfdate = (String) meta_hash.get("DateTime"); sfdate = sfdate.replaceFirst(":", "-"); sfdate = sfdate.replaceFirst(":", "-")+".000"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); try { Date startDate = dateFormat.parse(FIXCH5_EARLIEST); Date endDate = dateFormat.parse(FIXCH5_LATEST); Date fileDate = dateFormat.parse(sfdate); if (fileDate.before(startDate) || fileDate.after(endDate)) { return -3; // too early or too late } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } final int [] patts = {0x060, 0x0e0}; // final int [] masks = {0x7e0, 0x7c0}; final int [] masks = {0x7c0, 0x780}; final int [] offs = {0x080, 0x100}; final TileNeibs tn = new TileNeibs(width,height); // int [] clusters = new int [width*height]; final Thread[] threads = ImageDtt.newThreadArray(ImageDtt.THREADS_MAX); final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ancorr = new AtomicInteger(0); for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { for (int ipix = ai.getAndIncrement(); ipix < pixels_in.length; ipix = ai.getAndIncrement()) { if (ipix == dbg_pix) { System.out.println("ipix==dbg_pix=="+ipix); } double dd = pixels_in[ipix]; int id = (int) dd; int mode = -1; for (int i = 0; i < patts.length; i++) { if (((id ^ patts[i]) & masks[i]) == 0) { mode = i; break; } } if (mode >= 0) { // int px = ipix % width; // int py = ipix / width; int npix = 0; double sd = 0; for (int dir = 0; dir < TileNeibs.DIRS; dir++) { int ipix1 = tn.getNeibIndex(ipix, dir); if (ipix1 >= 0) { sd+= pixels_in[ipix1]; npix++; } } if (npix > 0) { // always sd /= npix; if ((sd - dd) > (offs[mode]/2)) { pixels[ipix] += offs[mode]; ancorr.getAndIncrement(); } } } } } }; } ImageDtt.startAndJoin(threads); return ancorr.get(); // number of corrected pixels } // fixing "00:0E:64:10:C4:35" camera // fixing "00:0E:64:10:C4:35" camera public int fix000E6410C435( public int fix000E6410C435( Loading