Permalink
Browse files

Changed masking so Isis special pixel types could not be used in calc…

…ulating the statistics of an image. I also change the image's normalization to normalize with data in the range of +-2 sigmas of the mean. This seems to work well with data not condition properly, it remains unseen what this might do to the fancy prepared Apollo metric data.
  • Loading branch information...
1 parent 72b6cde commit dc45805875196507716d8bc48d3cd74d529789bd Zack Moratto committed Aug 9, 2009
View
50 src/Isis/DiskImageResourceIsis.cc
@@ -37,6 +37,7 @@
// Isis Includes
#include <Cube.h>
#include <Portal.h>
+#include <SpecialPixel.h>
using namespace std;
using namespace boost;
@@ -180,4 +181,53 @@ namespace vw {
{
return new DiskImageResourceIsis(filename, format);
}
+
+ /// Info about special pixel types in ISIS
+ // --------------------------------------
+ double DiskImageResourceIsis::nodata_value() const {
+ switch (m_format.channel_type) {
+ case VW_CHANNEL_FLOAT64:
+ return Isis::NULL8;
+ case VW_CHANNEL_FLOAT32:
+ return Isis::NULL4;
+ case VW_CHANNEL_INT32:
+ return Isis::INULL4;
+ case VW_CHANNEL_INT16:
+ return Isis::NULL2;
+ default:
+ return 0.0;
+ }
+ }
+ double DiskImageResourceIsis::valid_minimum() const {
+ switch (m_format.channel_type) {
+ case VW_CHANNEL_FLOAT64:
+ return Isis::ValidMinimum;
+ case VW_CHANNEL_FLOAT32:
+ return Isis::VALID_MIN4;
+ case VW_CHANNEL_INT32:
+ return Isis::IVALID_MIN4;
+ case VW_CHANNEL_INT16:
+ return Isis::VALID_MIN2;
+ case VW_CHANNEL_UINT16:
+ return Isis::VALID_MINU2;
+ default:
+ return Isis::VALID_MIN1;
+ }
+ }
+ double DiskImageResourceIsis::valid_maximum() const {
+ switch (m_format.channel_type) {
+ case VW_CHANNEL_FLOAT64:
+ return Isis::ValidMaximum;
+ case VW_CHANNEL_FLOAT32:
+ return Isis::VALID_MAX4;
+ case VW_CHANNEL_INT32:
+ return 2147483647;
+ case VW_CHANNEL_INT16:
+ return Isis::VALID_MAX2;
+ case VW_CHANNEL_UINT16:
+ return Isis::VALID_MAXU2;
+ default:
+ return Isis::VALID_MAX1;
+ }
+ }
}
View
11 src/Isis/DiskImageResourceIsis.h
@@ -64,6 +64,17 @@ namespace vw {
static DiskImageResource* construct_create(std::string const& filename,
ImageFormat const& format);
+ // Info about special pixel types in ISIS
+ // --------------------------------------
+ // Note: Isis has many types of invalid pixels. If creating a mask
+ // of valid pixels, please use only pixels within the valid range
+ // provided in the functions below.
+ bool has_nodata_value() const { return true; }
+ double nodata_value() const;
+ double valid_minimum() const;
+ double valid_maximum() const;
+
+
private:
std::string m_filename;
View
71 src/Isis/StereoSessionIsis.cc
@@ -36,6 +36,7 @@
#include <Isis/IsisCameraModel.h>
#include <StereoSettings.h>
#include <Isis/IsisAdjustCameraModel.h>
+#include <Isis/DiskImageResourceIsis.h>
// Boost
#include <boost/filesystem/operations.hpp>
@@ -214,8 +215,8 @@ void StereoSessionIsis::pre_preprocessing_hook(std::string const& input_file1, s
output_file1 = m_out_prefix + "-L.tif";
output_file2 = m_out_prefix + "-R.tif";
- DiskImageResourceGDAL left_rsrc(input_file1);
- DiskImageResourceGDAL right_rsrc(input_file2);
+ DiskImageResourceIsis left_rsrc(input_file1);
+ DiskImageResourceIsis right_rsrc(input_file2);
GeoReference input_georef1, input_georef2;
// Disabled for now since we haven't really figured how to
@@ -233,25 +234,42 @@ void StereoSessionIsis::pre_preprocessing_hook(std::string const& input_file1, s
// Make sure the images are normalized
vw_out(InfoMessage) << "\t--> Computing min/max values for normalization.\n";
float left_lo, left_hi, right_lo, right_hi;
- if (left_rsrc.has_nodata_value()) {
- double left_nodata = left_rsrc.nodata_value();
- std::cout << "\t Using nodata value for left image: " << left_nodata << "\n";
- min_max_channel_values(create_mask(left_disk_image, left_nodata), left_lo, left_hi);
- } else {
- min_max_channel_values(left_disk_image, left_lo, left_hi);
- }
- vw_out(InfoMessage) << "\t Left: [" << left_lo << " " << left_hi << "] \n";
- if (right_rsrc.has_nodata_value()) {
- double right_nodata = right_rsrc.nodata_value();
- std::cout << "\t Using nodata value for right image: " << right_nodata << "\n";
- min_max_channel_values(create_mask(right_disk_image, right_nodata), right_lo, right_hi);
- } else {
- min_max_channel_values(create_mask(right_disk_image), right_lo, right_hi);
+ float left_mean, left_std, right_mean, right_std;
+ min_max_channel_values(create_mask(left_disk_image, left_rsrc.valid_minimum(),
+ left_rsrc.valid_maximum()), left_lo, left_hi);
+ left_mean = mean_channel_value(create_mask(left_disk_image, left_rsrc.valid_minimum(),
+ left_rsrc.valid_maximum()));
+ left_std = stddev_channel_value(create_mask(left_disk_image,left_rsrc.valid_minimum(),
+ left_rsrc.valid_maximum()));
+ vw_out(InfoMessage) << "\t Left: [ lo:" << left_lo << " hi:" << left_hi
+ << " m:" << left_mean << " s:" << left_std << "]\n";
+ min_max_channel_values(create_mask(right_disk_image, right_rsrc.valid_minimum(),
+ right_rsrc.valid_maximum()), right_lo, right_hi);
+ right_mean = mean_channel_value(create_mask(right_disk_image, right_rsrc.valid_minimum(),
+ right_rsrc.valid_maximum()));
+ right_std = stddev_channel_value(create_mask(right_disk_image,right_rsrc.valid_minimum(),
+ right_rsrc.valid_maximum()));
+ vw_out(InfoMessage) << "\t Right: [ lo:" << right_lo << " hi:" << right_hi
+ << " m:" << right_mean << " s:" << right_std << "]\n";
+
+ // Normalizing to -+2 sigmas around mean
+ if ( stereo_settings().force_max_min == 0 ) {
+ if ( left_lo < left_mean - 2*left_std )
+ left_lo = left_mean - 2*left_std;
+ if ( right_lo < right_mean - 2*right_std )
+ right_lo = right_mean - 2*right_std;
+ if ( left_hi > left_mean + 2*left_std )
+ left_hi = left_mean + 2*left_std;
+ if ( right_hi > right_mean + 2*right_std )
+ right_hi = right_mean + 2*right_std;
+
+ std::cout << "Changed left lo:" << left_lo << " hi:" << left_hi << std::endl;
+ std::cout << "Changed right lo:" << right_lo << " hi:" << right_hi << std::endl;
}
- vw_out(InfoMessage) << "\t Right: [" << right_lo << " " << right_hi << "]\n";
-
+
+ // Picking Global
float lo = std::min (left_lo, right_lo);
- float hi = std::min (left_hi, right_hi);
+ float hi = std::max (left_hi, right_hi);
// If this is a map projected cube, we skip the step of aligning the
// images, because the map projected images are probable very nearly
@@ -272,12 +290,13 @@ void StereoSessionIsis::pre_preprocessing_hook(std::string const& input_file1, s
ImageViewRef<PixelGray<float> > Limg;
ImageViewRef<PixelGray<float> > Rimg;
if (stereo_settings().individually_normalize == 0 ) {
- Limg = normalize(remove_isis_special_pixels(left_disk_image, lo), lo, hi, 0, 1.0);
- Rimg = crop(transform(normalize(remove_isis_special_pixels(right_disk_image, lo), lo, hi, 0, 1.0),trans2),common_bbox);
+ vw_out(0) << "\t--> Normalizing globally to: ["<<lo<<" "<<hi<<"]\n";
+ Limg = normalize(remove_isis_special_pixels(left_disk_image, lo), lo, hi,0.0,1.0);
+ Rimg = crop(transform(normalize(remove_isis_special_pixels(right_disk_image, lo), lo, hi,0.0,1.0),trans2),common_bbox);
} else {
vw_out(0) << "\t--> Individually normalizing.\n";
- Limg = normalize(remove_isis_special_pixels(left_disk_image, left_lo));
- Rimg = crop(transform(normalize(remove_isis_special_pixels(right_disk_image, right_lo)),trans2),common_bbox);
+ Limg = normalize(remove_isis_special_pixels(left_disk_image, left_lo),left_lo,left_hi,0.0,1.0);
+ Rimg = crop(transform(normalize(remove_isis_special_pixels(right_disk_image, right_lo),right_lo,right_hi,0.0,1.0),trans2),common_bbox);
}
// Write the results to disk.
@@ -301,14 +320,15 @@ void StereoSessionIsis::pre_preprocessing_hook(std::string const& input_file1, s
ImageViewRef<PixelGray<uint8> > Limg;
ImageViewRef<PixelGray<uint8> > Rimg;
if (stereo_settings().individually_normalize == 0 ) {
+ vw_out(0) << "\t--> Normalizing globally to: ["<<lo<<" "<<hi<<"]\n";
Limg = channel_cast_rescale<uint8>(normalize(remove_isis_special_pixels(left_disk_image, lo),lo,hi,0.0,1.0));
Rimg = channel_cast_rescale<uint8>(transform(normalize(remove_isis_special_pixels(right_disk_image,lo),lo,hi,0.0,1.0),
HomographyTransform(align_matrix),
left_disk_image.cols(), left_disk_image.rows()));
} else {
vw_out(0) << "\t--> Individually normalizing.\n";
- Limg = channel_cast_rescale<uint8>(normalize(remove_isis_special_pixels(left_disk_image, left_lo)));
- Rimg = channel_cast_rescale<uint8>(transform(normalize(remove_isis_special_pixels(right_disk_image,right_lo)),
+ Limg = channel_cast_rescale<uint8>(normalize(remove_isis_special_pixels(left_disk_image, left_lo),left_lo,left_hi,0.0,1.0));
+ Rimg = channel_cast_rescale<uint8>(transform(normalize(remove_isis_special_pixels(right_disk_image,right_lo),right_lo,right_hi,0.0,1.0),
HomographyTransform(align_matrix),
left_disk_image.cols(), left_disk_image.rows()));
}
@@ -443,3 +463,4 @@ boost::shared_ptr<vw::camera::CameraModel> StereoSessionIsis::camera_model(std::
}
+
View
1 src/StereoSettings.cc
@@ -99,6 +99,7 @@ StereoSettings::StereoSettings() {
ASSOC_INT("DO_INTERESTPOINT_ALIGNMENT", keypoint_alignment, 0, "Align images using the keypoint alignment method");
ASSOC_INT("INTERESTPOINT_ALIGNMENT_SUBSAMPLING", keypoint_align_subsampling, 1, "Image sub-sampling factor for keypoint alignment.");
ASSOC_INT("DO_INDIVIDUAL_NORMALIZATION", individually_normalize, 0, "Normalize each image individually before processsing.");
+ ASSOC_INT("FORCE_USE_ENTIRE_RANGE", force_max_min, 0, "Use images entire values, otherwise compress image range to -+2.5 sigmas around mean.");
// Correlation Options
ASSOC_INT("DO_SLOG", slog, 1, "perform an slog (relpace the emboss)");
View
3 src/StereoSettings.h
@@ -46,7 +46,8 @@ class StereoSettings {
int epipolar_alignment; /* Align images using the epipolar constraints */
int keypoint_alignment; /* Align images using the keypoint alignment method */
int keypoint_align_subsampling; // if > 1, image sub-sampling factor for keypoint aligment (to speed things up)
- int individually_normalize; // if > 1, normalize the images individually with their own hi's and low. Default = 0 means we pick a global high and low.
+ int individually_normalize; // if > 1, normalize the images individually with their own hi's and low
+ int force_max_min; // Use entire dynamic range of image..
// Correlation Options
int slog; /* perform an slog (relpace the emboss) */
View
2 stereo.default.example
@@ -5,6 +5,8 @@
DO_INTERESTPOINT_ALIGNMENT 1
DO_EPIPOLAR_ALIGNMENT 0
INTERESTPOINT_ALIGNMENT_SUBSAMPLING 1
+DO_INDIVIDUAL_NORMALIZATION 0
+FORCE_USE_ENTIRE_RANGE 0
# Choose whether to do the SLOG or log of the image (or neither)
# (choosing both will default to only SLOG)

0 comments on commit dc45805

Please sign in to comment.