From 3ec97a169df45ddaeb199de3c1cdb3758c8f1e6a Mon Sep 17 00:00:00 2001 From: Cheng-Chin Chiang Date: Fri, 18 Aug 2023 15:57:52 +0800 Subject: [PATCH] Fixed the lack of mask for LEL images (#1292) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed the lack of mask for LEL images * Add a check for the LEL image mask data --------- Co-authored-by: Adrianna PiƄska --- CHANGELOG.md | 1 + src/ImageData/FileLoader.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 481ab700c..91249ff6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed the case-sensitive of reading BUNIT from a file header ([#1187](https://github.com/CARTAvis/carta-backend/issues/1187)). * Fixed the crash when reading beam table with 64-bit floats ([#1166](https://github.com/CARTAvis/carta-backend/issues/1166)). * Fixed region spectral profile from FITS gz image ([#1271](https://github.com/CARTAvis/carta-backend/issues/1271)). +* Fixed the lack of mask for LEL images ([#1291](https://github.com/CARTAvis/carta-backend/issues/1291)). * Fixed file path to save generated image ([#1252](https://github.com/CARTAvis/carta-backend/issues/1252)). ## [4.0.0-beta.1] diff --git a/src/ImageData/FileLoader.cc b/src/ImageData/FileLoader.cc index 7c6acaea7..1fe67cf50 100644 --- a/src/ImageData/FileLoader.cc +++ b/src/ImageData/FileLoader.cc @@ -339,6 +339,24 @@ bool FileLoader::GetSlice(casacore::Array& data, const StokesSlicer& stok // Use ImageExpr for slice casacore::Array slice_data; image->doGetSlice(slice_data, slicer); + + if (image->isMasked()) { + // Get mask data + casacore::Array mask_data; + image->getMaskSlice(mask_data, slicer); + + if (mask_data.shape() == slice_data.shape()) { + // Reset the pixel value as NaN if its mask is false + casacore::Array::iterator slice_data_iter = slice_data.begin(); + casacore::Array::iterator mask_data_iter = mask_data.begin(); + for (; slice_data_iter != slice_data.end(); ++slice_data_iter, ++mask_data_iter) { + if (!*mask_data_iter) { + *slice_data_iter = NAN; + } + } + } + } + data = slice_data; // copy from reference return true; } else if (image_type == "RebinImage") {