ROIFilter: Add filter to only preserve ROI regions
This commit is contained in:
@@ -168,6 +168,122 @@ TEST_CASE("FrameTransformation_Converted_bshuf_lz4" ,"") {
|
||||
REQUIRE(input_1[(511+512)*1024 + 800] == output[CONVERTED_MODULE_SIZE * (nmodules - 2) + 1030 + 800 + 6]);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("FrameTransformation_Converted_bshuf_lz4_roi" ,"") {
|
||||
const uint16_t nmodules = 4;
|
||||
const uint16_t ndatastreams = 2;
|
||||
DiffractionExperiment experiment(DetectorGeometry(ndatastreams * nmodules, 2));
|
||||
experiment.DataStreams(ndatastreams);
|
||||
|
||||
experiment.Mode(DetectorMode::Conversion).Compression(JFJochProtoBuf::BSHUF_LZ4);
|
||||
|
||||
FrameTransformation transformation(experiment);
|
||||
|
||||
ROIFilter filter(experiment.GetXPixelsNum(), experiment.GetYPixelsNum(), 0);
|
||||
filter.SetRectangle(100, 20, 10, 10);
|
||||
|
||||
std::vector<int16_t> input_0(nmodules*RAW_MODULE_SIZE);
|
||||
for (int i = 0; i < nmodules*RAW_MODULE_SIZE; i++)
|
||||
input_0[i] = 50;
|
||||
|
||||
std::vector<int16_t> input_1(nmodules*RAW_MODULE_SIZE);
|
||||
for (int i = 0; i < nmodules*RAW_MODULE_SIZE; i++)
|
||||
input_1[i] = 50;
|
||||
|
||||
std::vector<char> output_compressed(experiment.GetMaxCompressedSize());
|
||||
|
||||
for (int i = 0; i < nmodules; i++) {
|
||||
REQUIRE_NOTHROW(transformation.ProcessModule(input_0.data() + i * RAW_MODULE_SIZE, i, 0));
|
||||
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
|
||||
}
|
||||
|
||||
size_t compressed_size;
|
||||
transformation.Pack();
|
||||
transformation.ApplyROI(filter);
|
||||
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
|
||||
output_compressed.resize(compressed_size);
|
||||
|
||||
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
|
||||
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
|
||||
|
||||
std::vector<int16_t> output;
|
||||
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithmEnum(), output_compressed,
|
||||
experiment.GetPixelsNum()));
|
||||
|
||||
size_t diff = 0;
|
||||
for (int y = 0; y < experiment.GetYPixelsNum(); y++) {
|
||||
for (int x = 0; x < experiment.GetXPixelsNum(); x++) {
|
||||
if ((y >= 20 ) && (y < 30) && (x >= 100) && (x < 110)) {
|
||||
if (output[y * experiment.GetXPixelsNum() + x] != 50)
|
||||
diff++;
|
||||
} else {
|
||||
if (output[y * experiment.GetXPixelsNum() + x] != INT16_MIN)
|
||||
diff++;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(diff == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("FrameTransformation_Converted_bshuf_lz4_roi_summation" ,"") {
|
||||
const uint16_t nmodules = 4;
|
||||
const uint16_t ndatastreams = 2;
|
||||
const uint16_t nframes = 4;
|
||||
DiffractionExperiment experiment(DetectorGeometry(ndatastreams * nmodules, 2));
|
||||
experiment.DataStreams(ndatastreams);
|
||||
|
||||
experiment.Mode(DetectorMode::Conversion).Compression(JFJochProtoBuf::BSHUF_LZ4).Summation(nframes);
|
||||
|
||||
FrameTransformation transformation(experiment);
|
||||
|
||||
ROIFilter filter(experiment.GetXPixelsNum(), experiment.GetYPixelsNum(), 0);
|
||||
filter.SetRectangle(100, 20, 10, 10);
|
||||
|
||||
std::vector<int16_t> input_0(nmodules*RAW_MODULE_SIZE);
|
||||
for (int i = 0; i < nmodules*RAW_MODULE_SIZE; i++)
|
||||
input_0[i] = 50;
|
||||
|
||||
std::vector<int16_t> input_1(nmodules*RAW_MODULE_SIZE);
|
||||
for (int i = 0; i < nmodules*RAW_MODULE_SIZE; i++)
|
||||
input_1[i] = 50;
|
||||
|
||||
std::vector<char> output_compressed(experiment.GetMaxCompressedSize());
|
||||
|
||||
for (int f = 0; f < nframes; f++) {
|
||||
for (int i = 0; i < nmodules; i++) {
|
||||
REQUIRE_NOTHROW(transformation.ProcessModule(input_0.data() + i * RAW_MODULE_SIZE, i, 0));
|
||||
REQUIRE_NOTHROW(transformation.ProcessModule(input_1.data() + i * RAW_MODULE_SIZE, i, 1));
|
||||
}
|
||||
}
|
||||
|
||||
size_t compressed_size;
|
||||
transformation.Pack();
|
||||
transformation.ApplyROI(filter);
|
||||
REQUIRE_NOTHROW(compressed_size = transformation.SaveCompressedImage(output_compressed.data()));
|
||||
output_compressed.resize(compressed_size);
|
||||
|
||||
REQUIRE(bshuf_read_uint64_BE(output_compressed.data()) == experiment.GetPixelsNum() * experiment.GetPixelDepth());
|
||||
REQUIRE(bshuf_read_uint32_BE(output_compressed.data()+8) == JFJochBitShuffleCompressor::DefaultBlockSize * experiment.GetPixelDepth());
|
||||
|
||||
std::vector<int32_t> output;
|
||||
REQUIRE_NOTHROW(JFJochDecompress(output, experiment.GetCompressionAlgorithmEnum(), output_compressed,
|
||||
experiment.GetPixelsNum()));
|
||||
|
||||
size_t diff = 0;
|
||||
for (int y = 0; y < experiment.GetYPixelsNum(); y++) {
|
||||
for (int x = 0; x < experiment.GetXPixelsNum(); x++) {
|
||||
if ((y >= 20 ) && (y < 30) && (x >= 100) && (x < 110)) {
|
||||
if (output[y * experiment.GetXPixelsNum() + x] != nframes * 50)
|
||||
diff++;
|
||||
} else {
|
||||
if (output[y * experiment.GetXPixelsNum() + x] != INT32_MIN)
|
||||
diff++;
|
||||
}
|
||||
}
|
||||
}
|
||||
REQUIRE(diff == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("FrameTransformation_Converted_bshuf_zstd" ,"") {
|
||||
const uint16_t nmodules = 4;
|
||||
const uint16_t ndatastreams = 2;
|
||||
|
||||
Reference in New Issue
Block a user