From e9b2411de4c5ecc2c13142024907e33ca529b075 Mon Sep 17 00:00:00 2001 From: Aang23 Date: Mon, 12 Apr 2021 20:20:25 +0200 Subject: [PATCH] Loads of VIIRS fixes --- .../jpss/instruments/viirs/channel_reader.cpp | 38 ++---- .../jpss/instruments/viirs/channel_reader.h | 1 - .../modules/jpss/instruments/viirs/channels.h | 49 +++---- .../instruments/viirs/module_jpss_viirs.cpp | 120 +++--------------- 4 files changed, 49 insertions(+), 159 deletions(-) diff --git a/src-core/modules/jpss/instruments/viirs/channel_reader.cpp b/src-core/modules/jpss/instruments/viirs/channel_reader.cpp index f5bd6ccc2..ee9bbbd60 100644 --- a/src-core/modules/jpss/instruments/viirs/channel_reader.cpp +++ b/src-core/modules/jpss/instruments/viirs/channel_reader.cpp @@ -51,16 +51,6 @@ namespace jpss BodyPacket body(packet); if (body.detector <= channelSettings.zoneHeight) - segments[currentSegment - 1].body[body.detector] = body; - } - } - - void VIIRSReader::process() - { - for (Segment &seg : segments) - { - // Decompress everything - for (BodyPacket &body : seg.body) { if (!body.empty) { @@ -105,6 +95,8 @@ namespace jpss } } } + + segments[currentSegment - 1].body[body.detector] = body; } } } @@ -117,7 +109,7 @@ namespace jpss Segment &segInit = channelSource.segments[segment_number]; Segment &segCurrent = segments[segment_number]; - for (int body_number = 0; body_number < 31; body_number++) + for (int body_number = 0; body_number < 32; body_number++) { BodyPacket &bodyInit = segInit.body[body_number / deci]; BodyPacket &bodyCurrent = segCurrent.body[body_number]; @@ -149,9 +141,6 @@ namespace jpss for (int y = 0; y < channelSettings.zoneHeight; y++) { - //if(y == 0 || y == 1 || y == 1 || y == 14) - // continue; - BodyPacket &body = seg.body[y]; if (!body.empty) @@ -163,22 +152,7 @@ namespace jpss // Check if this detector is valid if (body.detectors[det].data_payload_size > 8 && (body.detectors[det].sync_word == body.sync_word_pattern || body.detectors[det].sync_word == 0xC000FFEE)) { - //for (int z = 0; z < channelSettings.zoneWidth[det]; z++) - // body.detectors[det].decompressedPayload[z] *= 4.0f; - - // Cleanup garbage data on the edges, Moderate channels - if (channelSettings.zoneHeight == 15 && (det == 0 || det == 5) && (y == 0 || y == 1 || y == 14)) - std::fill(&imageBuffer.get()[lines * channelSettings.totalWidth + offset], &imageBuffer.get()[lines * channelSettings.totalWidth + offset + channelSettings.zoneWidth[det] - 1], 0); - else if (channelSettings.zoneHeight == 15 && (det == 1 || det == 4) && y == 0) - std::fill(&imageBuffer.get()[lines * channelSettings.totalWidth + offset], &imageBuffer.get()[lines * channelSettings.totalWidth + offset + channelSettings.zoneWidth[det] - 1], 0); - // Cleanup garbage data on the edges, Imaging channels - else if (channelSettings.zoneHeight == 31 && (det == 0 || det == 5) && (y == 0 || y == 1 || y == 2 || y == 3 || y == 30 || y == 29 || y == 28)) - std::fill(&imageBuffer.get()[lines * channelSettings.totalWidth + offset], &imageBuffer.get()[lines * channelSettings.totalWidth + offset + channelSettings.zoneWidth[det] - 1], 0); - else if (channelSettings.zoneHeight == 31 && (det == 1 || det == 4) && (y == 0 || y == 1 || y == 30)) - std::fill(&imageBuffer.get()[lines * channelSettings.totalWidth + offset], &imageBuffer.get()[lines * channelSettings.totalWidth + offset + channelSettings.zoneWidth[det] - 1], 0); - // Write actual data - else - std::memcpy(&imageBuffer.get()[lines * channelSettings.totalWidth + offset], body.detectors[det].decompressedPayload, channelSettings.zoneWidth[det] * 2); + std::memcpy(&imageBuffer.get()[lines * channelSettings.totalWidth + offset], body.detectors[det].decompressedPayload, channelSettings.zoneWidth[det] * 2); } else { @@ -200,6 +174,10 @@ namespace jpss } } + // Scale bit depth + for (int i = 0; i < channelSettings.totalWidth * lines; i++) + imageBuffer.get()[i] *= channelSettings.scale; + cimg_library::CImg image = cimg_library::CImg(imageBuffer.get(), channelSettings.totalWidth, lines); if (channelSettings.invert) diff --git a/src-core/modules/jpss/instruments/viirs/channel_reader.h b/src-core/modules/jpss/instruments/viirs/channel_reader.h index db0c8ef2f..570f1d055 100644 --- a/src-core/modules/jpss/instruments/viirs/channel_reader.h +++ b/src-core/modules/jpss/instruments/viirs/channel_reader.h @@ -29,7 +29,6 @@ namespace jpss VIIRSReader(Channel &ch); ~VIIRSReader(); void feed(ccsds::ccsds_1_0_1024::CCSDSPacket &packet); - void process(); void differentialDecode(VIIRSReader &channelSource, int deci); cimg_library::CImg getImage(); }; diff --git a/src-core/modules/jpss/instruments/viirs/channels.h b/src-core/modules/jpss/instruments/viirs/channels.h index 1988c09d4..c6f524f9d 100644 --- a/src-core/modules/jpss/instruments/viirs/channels.h +++ b/src-core/modules/jpss/instruments/viirs/channels.h @@ -15,60 +15,61 @@ namespace jpss int totalWidth; int oversampleZone[6]; bool invert; + float scale; // Coef to get the data to 16-bits }; // All channels static std::unordered_map VIIRSChannels = { // M4 - {800, {800, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, false}}, + {800, {800, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, false, 8}}, // M5 - {801, {801, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, false}}, + {801, {801, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, false, 8}}, // M3 - {802, {802, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, false}}, + {802, {802, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, false, 8}}, // M2 - {803, {803, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, false}}, + {803, {803, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, false, 8}}, // M1 - {804, {804, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, false}}, + {804, {804, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, false, 8}}, // M6 - {805, {805, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, true}}, + {805, {805, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, false, 16}}, // M7 - {806, {806, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, false}}, + {806, {806, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, false, 8}}, // M9 - {807, {807, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, false}}, + {807, {807, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, false, 16}}, // M10 - {808, {808, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, false}}, + {808, {808, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, false, 16}}, // M8 - {809, {809, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, false}}, + {809, {809, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, false, 16}}, // M11 - {810, {810, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, false}}, + {810, {810, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, false, 16}}, // M13 - {811, {811, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 2, 3, 3, 2, 1}, true}}, + {811, {811, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 2, 3, 3, 2, 1}, true, 8}}, // M12 - {812, {812, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, false}}, + {812, {812, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, false, 16}}, // M16 - {814, {814, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, true}}, + {814, {814, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, true, 16}}, // M15 - {815, {815, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, true}}, + {815, {815, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, true, 16}}, // M14 - {816, {816, {640, 368, 592, 592, 368, 640}, 15, 3200, {1, 1, 1, 1, 1, 1}, true}}, + {816, {816, {640, 368, 592, 592, 368, 640}, 16, 3200, {1, 1, 1, 1, 1, 1}, true, 16}}, // I1 - {818, {818, {1280, 736, 1184, 1184, 736, 1280}, 31, 6400, {1, 1, 1, 1, 1, 1}, false}}, + {818, {818, {1280, 736, 1184, 1184, 736, 1280}, 32, 6400, {1, 1, 1, 1, 1, 1}, false, 16}}, // I2 - {819, {819, {1280, 736, 1184, 1184, 736, 1280}, 31, 6400, {1, 1, 1, 1, 1, 1}, false}}, + {819, {819, {1280, 736, 1184, 1184, 736, 1280}, 32, 6400, {1, 1, 1, 1, 1, 1}, false, 16}}, // I3 - {820, {820, {1280, 736, 1184, 1184, 736, 1280}, 31, 6400, {1, 1, 1, 1, 1, 1}, false}}, + {820, {820, {1280, 736, 1184, 1184, 736, 1280}, 32, 6400, {1, 1, 1, 1, 1, 1}, false, 16}}, // I4 - {813, {813, {1280, 736, 1184, 1184, 736, 1280}, 31, 6400, {1, 1, 1, 1, 1, 1}, true}}, + {813, {813, {1280, 736, 1184, 1184, 736, 1280}, 32, 6400, {1, 1, 1, 1, 1, 1}, true, 16}}, // I5 - {817, {817, {1280, 736, 1184, 1184, 736, 1280}, 31, 6400, {1, 1, 1, 1, 1, 1}, true}}, + {817, {817, {1280, 736, 1184, 1184, 736, 1280}, 32, 6400, {1, 1, 1, 1, 1, 1}, true, 16}}, // DNB - {821, {821, {784, 488, 760, 760, 488, 784}, 15, 4064, {1, 1, 1, 1, 1, 1}, false}}, + {821, {821, {784, 488, 760, 760, 488, 784}, 16, 4064, {1, 1, 1, 1, 1, 1}, false, 2}}, // DNB MGS - {822, {822, {784, 488, 760, 760, 488, 784}, 15, 4064, {1, 1, 1, 1, 1, 1}, false}}, + {822, {822, {784, 488, 760, 760, 488, 784}, 16, 4064, {1, 1, 1, 1, 1, 1}, false, 2}}, // DNB LGS - {823, {823, {784, 488, 760, 760, 488, 784}, 15, 4064, {1, 1, 1, 1, 1, 1}, false}} + {823, {823, {784, 488, 760, 760, 488, 784}, 16, 4064, {1, 1, 1, 1, 1, 1}, false, 2}} }; } // namespace viirs diff --git a/src-core/modules/jpss/instruments/viirs/module_jpss_viirs.cpp b/src-core/modules/jpss/instruments/viirs/module_jpss_viirs.cpp index 253229a40..5c4c2630c 100644 --- a/src-core/modules/jpss/instruments/viirs/module_jpss_viirs.cpp +++ b/src-core/modules/jpss/instruments/viirs/module_jpss_viirs.cpp @@ -147,39 +147,6 @@ namespace jpss logger->info("VCID 16 Frames : " + std::to_string(vcidFrames)); logger->info("CCSDS Frames : " + std::to_string(ccsds_frames)); - // Process them all - logger->info("Decompressing and decoding channels... (Can take a while)"); - - // Moderate resolution channels - reader_m4.process(); - reader_m5.process(); - reader_m3.process(); - reader_m2.process(); - reader_m1.process(); - reader_m6.process(); - reader_m7.process(); - reader_m9.process(); - reader_m10.process(); - reader_m8.process(); - reader_m11.process(); - reader_m13.process(); - reader_m12.process(); - reader_m16.process(); - reader_m15.process(); - reader_m14.process(); - - // Imaging channels - reader_i1.process(); - reader_i2.process(); - reader_i3.process(); - reader_i4.process(); - reader_i5.process(); - - // DNB channels - reader_dnb.process(); - reader_dnb_mgs.process(); - reader_dnb_lgs.process(); - // Differential decoding for M5, M3, M2, M1 logger->info("Diff M5..."); { @@ -317,9 +284,10 @@ namespace jpss image_i4 = bowtie::correctGenericBowTie(image_i4, 1, reader_i4.channelSettings.zoneHeight, alpha, beta); image_i5 = bowtie::correctGenericBowTie(image_i5, 1, reader_i5.channelSettings.zoneHeight, alpha, beta); - image_dnb = bowtie::correctGenericBowTie(image_dnb, 1, reader_dnb.channelSettings.zoneHeight, alpha, beta); - image_dnb_lgs = bowtie::correctGenericBowTie(image_dnb_lgs, 1, reader_dnb_lgs.channelSettings.zoneHeight, alpha, beta); - image_dnb_mgs = bowtie::correctGenericBowTie(image_dnb_mgs, 1, reader_dnb_mgs.channelSettings.zoneHeight, alpha, beta); + // DNB has no Bowtie + //image_dnb = bowtie::correctGenericBowTie(image_dnb, 1, reader_dnb.channelSettings.zoneHeight, alpha, beta); + //image_dnb_lgs = bowtie::correctGenericBowTie(image_dnb_lgs, 1, reader_dnb_lgs.channelSettings.zoneHeight, alpha, beta); + //image_dnb_mgs = bowtie::correctGenericBowTie(image_dnb_mgs, 1, reader_dnb_mgs.channelSettings.zoneHeight, alpha, beta); // Correct mirrored channels image_i1.mirror('x'); @@ -352,66 +320,7 @@ namespace jpss for (int i = 0; i < image_dnb_night.height() * image_dnb_night.width(); i++) image_dnb_night.data()[i] *= 15; - // Histogram equalization so it doesn't look like crap - logger->info("Equalizing imaging channels..."); - image_i1.equalize(1000); - image_i2.equalize(1000); - image_i3.equalize(1000); - image_i4.equalize(1000); - image_i5.equalize(1000); - - logger->info("Equalizing moderate channels..."); - image_m1.equalize(1000); - image_m2.equalize(1000); - image_m3.equalize(1000); - image_m4.equalize(1000); - image_m5.equalize(1000); - image_m6.equalize(1000); - image_m7.equalize(1000); - image_m8.equalize(1000); - image_m9.equalize(1000); - image_m10.equalize(1000); - image_m11.equalize(1000); - image_m12.equalize(1000); - image_m13.equalize(1000); - image_m14.equalize(1000); - image_m15.equalize(1000); - image_m16.equalize(1000); - - logger->info("Equalizing DNB channels..."); - image_dnb.equalize(1000); - image_dnb_lgs.equalize(1000); - image_dnb_mgs.equalize(1000); - - logger->info("White balancing all channels..."); - image::white_balance(image_i1, 0.05f, 1); - image::white_balance(image_i2, 0.05f, 1); - image::white_balance(image_i3, 0.05f, 1); - image::white_balance(image_i4, 0.05f, 1); - image::white_balance(image_i5, 0.05f, 1); - - image::white_balance(image_m1, 0.05f, 1); - image::white_balance(image_m2, 0.05f, 1); - image::white_balance(image_m3, 0.05f, 1); - image::white_balance(image_m4, 0.05f, 1); - image::white_balance(image_m6, 0.05f, 1); - image::white_balance(image_m7, 0.05f, 1); - image::white_balance(image_m8, 0.05f, 1); - image::white_balance(image_m9, 0.05f, 1); - image::white_balance(image_m10, 0.05f, 1); - image::white_balance(image_m11, 0.05f, 1); - image::white_balance(image_m12, 0.05f, 1); - image::white_balance(image_m13, 0.05f, 1); - image::white_balance(image_m14, 0.05f, 1); - image::white_balance(image_m15, 0.05f, 1); - image::white_balance(image_m16, 0.05f, 1); - - image::white_balance(image_dnb, 0.05f, 1); - image::white_balance(image_dnb_lgs, 0.05f, 1); - image::white_balance(image_dnb_mgs, 0.05f, 1); - // Takes a while so we say how we're doing - if (image_m1.height() > 0) { logger->info("Channel M1..."); @@ -542,6 +451,9 @@ namespace jpss { logger->info("Channel DNB..."); WRITE_IMAGE(image_dnb, directory + "/VIIRS-DNB.png"); + image_dnb.equalize(1000); + image_dnb.normalize(0, 65535); + WRITE_IMAGE(image_dnb, directory + "/VIIRS-DNB-EQU.png"); } if (image_dnb_night.height() > 0) @@ -577,10 +489,11 @@ namespace jpss image221.draw_image(0, 0, 0, 1, tempImage2); image221.draw_image(0, 0, 0, 2, tempImage1); image221.mirror('x'); - image221.equalize(1000); image::white_balance(image221); } WRITE_IMAGE(image221, directory + "/VIIRS-RGB-I221.png"); + image221.equalize(1000); + WRITE_IMAGE(image221, directory + "/VIIRS-RGB-I221-EQU.png"); } if (image_i1.height() > 0 && image_i2.height() > 0 && image_i3.height() > 0) @@ -598,10 +511,11 @@ namespace jpss image321.draw_image(0, 0, 0, 1, tempImage1); image321.draw_image(0, 0, 0, 2, tempImage2); image321.mirror('x'); - image321.equalize(1000); image::white_balance(image321); } WRITE_IMAGE(image321, directory + "/VIIRS-RGB-I312.png"); + image321.equalize(1000); + WRITE_IMAGE(image321, directory + "/VIIRS-RGB-I321-EQU.png"); } if (image_m4.height() > 0 && image_m5.height() > 0 && image_m3.height() > 0) @@ -615,9 +529,6 @@ namespace jpss tempImage5 = bowtie::correctGenericBowTie(tempImage5, 1, std::get<1>(correlatedChannels).channelSettings.zoneHeight, alpha, beta); tempImage4 = bowtie::correctGenericBowTie(tempImage4, 1, std::get<0>(correlatedChannels).channelSettings.zoneHeight, alpha, beta); tempImage3 = bowtie::correctGenericBowTie(tempImage3, 1, std::get<2>(correlatedChannels).channelSettings.zoneHeight, alpha, beta); - tempImage5.equalize(1000); - tempImage4.equalize(1000); - tempImage3.equalize(1000); image453.draw_image(0, 0, 0, 0, tempImage4); image453.draw_image(0, 0, 0, 1, tempImage5); image453.draw_image(0, 0, 0, 2, tempImage3); @@ -625,6 +536,8 @@ namespace jpss image::white_balance(image453); } WRITE_IMAGE(image453, directory + "/VIIRS-RGB-M453.png"); + image453.equalize(1000); + WRITE_IMAGE(image453, directory + "/VIIRS-RGB-M453-EQU.png"); } if (image_m4.height() > 0 && image_m5.height() > 0 && image_m3.height() > 0) @@ -638,9 +551,6 @@ namespace jpss tempImage5 = bowtie::correctGenericBowTie(tempImage5, 1, std::get<1>(correlatedChannels).channelSettings.zoneHeight, alpha, beta); tempImage4 = bowtie::correctGenericBowTie(tempImage4, 1, std::get<0>(correlatedChannels).channelSettings.zoneHeight, alpha, beta); tempImage3 = bowtie::correctGenericBowTie(tempImage3, 1, std::get<2>(correlatedChannels).channelSettings.zoneHeight, alpha, beta); - tempImage5.equalize(1000); - tempImage4.equalize(1000); - tempImage3.equalize(1000); image543.draw_image(0, 0, 0, 0, tempImage5); image543.draw_image(0, 0, 0, 1, tempImage4); image543.draw_image(0, 0, 0, 2, tempImage3); @@ -648,6 +558,8 @@ namespace jpss image::white_balance(image543); } WRITE_IMAGE(image543, directory + "/VIIRS-RGB-M543.png"); + image543.equalize(1000); + WRITE_IMAGE(image543, directory + "/VIIRS-RGB-M543-EQU.png"); } if (image_dnb.height() > 0 && image_m16.height() > 0) @@ -680,7 +592,7 @@ namespace jpss void JPSSVIIRSDecoderModule::drawUI(bool window) { - ImGui::Begin("JPSS VIIRS Decoder", NULL, window ? NULL : NOWINDOW_FLAGS ); + ImGui::Begin("JPSS VIIRS Decoder", NULL, window ? NULL : NOWINDOW_FLAGS); ImGui::ProgressBar((float)progress / (float)filesize, ImVec2(ImGui::GetWindowWidth() - 10, 20));