Skip to content

Commit

Permalink
updated filters and masks
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredmales committed Jul 4, 2024
1 parent 55914ba commit 3e1ed58
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 29 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ doc/html/*
doc/mxlib.tag.xml
doc/citelist*
doc/*.aux
mxlib_git_version.h
include/mxlib_uncomp_version.h
source/mxlib_comp_version.h
old/*
Expand All @@ -26,3 +27,10 @@ a.out
*.o
*.swp
.*~

#tests
tests/mxlibTest
tests/include/improc/imageMasks_test
tests/include/sigproc/signalWindows_test
tests/include/ao/sim/pyramidSensor_test

6 changes: 3 additions & 3 deletions include/improc/aperturePhotometer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class aperturePhotometer
* \overload
*
* \returns 0 on success
* \returns -1 on error
* \returns -1 on error f
*/
int resize( int sizeX, ///< [in] The new size in rows
int sizeY ///< [in] The new size in columns
Expand Down Expand Up @@ -287,8 +287,8 @@ int aperturePhotometer<realT>::cumPhotWork( std::vector<realT> & cumPhot,
realT maxr
)
{
realT xcen = 0.5*(m_indexIm.rows()-1);
realT ycen = 0.5*(m_indexIm.cols()-1);
realT xcen = m_xcen;//0.5*(m_indexIm.rows()-1);
realT ycen = m_ycen;//0.5*(m_indexIm.cols()-1);

if(maxr <= 0) maxr = m_radius.back();

Expand Down
2 changes: 1 addition & 1 deletion include/improc/imageFilters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void radprof( vecT & rad, ///< [out] the radius points for the prof
maxr = rv.back().r;

/*Now bin*/
floatT dr = 1.0;
floatT dr = 1;
floatT r0 = minr;
floatT r1 = minr + dr;
int i1=0, i2, n;
Expand Down
45 changes: 42 additions & 3 deletions include/improc/imageMasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ void maskCircle( arrayT & m, ///< [in.out] the image to
}

/// Mask an ellipse in an image.
/** The ellipse is describe by its center coordinates and x and y direction radii (the semi-major and -minor axes, in either order). Any value can be set for the mask,
* with 0 being the default.
/** The ellipse is describe by its center coordinates and x and y direction radii (the semi-major and -minor axes,
* in either order). Any value can be set for the mask,cwith 0 being the default.
*
* \tparam arrayT is an Eigen-like type.
*
Expand Down Expand Up @@ -504,6 +504,45 @@ void maskEllipse( arrayT & m, ///< [in.out] the image to
}
}

/// Mask a wedge in an image.
/** The wedge is describe by its center coordinate, central angle, and angular half-width. Any value can be set for the mask.
* Pixels outside the masked circle are not altered.
*
* \tparam arrayT is an Eigen-like type.
*
* \ingroup image_masks
*/
template<class arrayT>
void maskWedge( arrayT & m, ///< [in.out] the image to be masked, is modified.
typename arrayT::Scalar xcen, ///< [in] the x coordinate of the center of the circle
typename arrayT::Scalar ycen, ///< [in] the y coordinate of the center of the circle
typename arrayT::Scalar angCen, ///< [in] the central angle of the wedge, in degrees
typename arrayT::Scalar angHW, ///< [in] the angular half-wdith of the wedge, in degrees
typename arrayT::Scalar val = 0 ///< [in] [optional] the mask value. Default is 0.
)
{
size_t l0 = m.rows();
size_t l1 = m.cols();

typedef typename arrayT::Scalar angleT;

angleT dang;

for(size_t c=0; c < m.cols(); c++)
{
for(size_t r=0; r < m.rows(); r++)
{

dang = math::angleDiff<math::degreesT<angleT>>(math::rtod(atan2( c-ycen, r-xcen )), angCen);


if( dang > -angHW && dang <= angHW)
{
m(r,c) = val;
}
}
}
}

///Draw a thin (1-pixel) line from one point to another.
/** Calculates the line connecting the two points and sets the pixels along that line to the
Expand All @@ -514,7 +553,7 @@ void maskEllipse( arrayT & m, ///< [in.out] the image to
* \ingroup image_masks
*/
template<typename realT>
int drawLine( eigenImage<realT> & mask, ///< [in.out] [pre-allocated] The array in which to draw the line.
int drawLine( eigenImage<realT> & mask, ///< [in/out] [pre-allocated] The array in which to draw the line.
realT x0, ///< [in] The x coordinate of the first point
realT y0, ///< [in] The y coordinate of the first point
realT x1, ///< [in] The x coordinate of the second point
Expand Down
10 changes: 4 additions & 6 deletions include/math/geo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,18 @@ typename angleT::realT angleMod(typename angleT::realT q /**< [in] the angle */)
*
* \returns the difference of q2 and q1
*
* \tparam degrad controls whether this is in degrees (0, default) or radians (1)
* \tparam angleT controls whether this is in degrees (0, default) or radians (1)
* \tparam realT is the type in which to do arithmetic
*
* \test Verify compilation and calculations of math::angleDiff \ref tests_math_geo_angleDiff "[test doc]"
*
* \ingroup geo
*/
template<class angleT>
typename angleT::realT angleDiff( typename angleT::realT q1, ///< [in] angle to subtract from q2, in degrees.
typename angleT::realT q2 ///< [in] angle to subtract q1 from, in degrees.
typename angleT::realT angleDiff( typename angleT::realT q1, ///< [in] angle to subtract from q2.
typename angleT::realT q2 ///< [in] angle to subtract q1 from.
)
{
//typedef typename degradT::realT realT;

{
static_assert(std::is_floating_point<typename angleT::realT>::value, "angleDiff: realT must be floating point");

typename angleT::realT dq = q2-q1;
Expand Down
80 changes: 64 additions & 16 deletions include/wfp/imagingUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,36 +272,84 @@ void tiltWavefront( wavefrontT & complexWavefront,
}
}

template< typename imageT1, typename imageT2>
void extractBlock(imageT1 & im,
int imX0,
int imXsz,
int imY0,
int imYsz,
imageT2 & wf,
int wfX0,
int wfY0)
/// Extract a block from one image and insert it into a second
template< typename imageT1,
typename imageT2
>
void extractBlock(imageT1 & dest, ///< [in/out] the image in which to place the extracted block. Must be pre-allocated.
int imX0, ///< [in] the x/row-coord of the lower left pixel of the destination region.
int imXsz, ///< [in] the x size (number of rows) of the block
int imY0, ///< [in] the y/col-coord of the lower left pixel of the desination region
int imYsz, ///< [in] the y=size (number of cols) ov the block
imageT2 & src, ///< [in] the source of the block. Must be large enough.
int wfX0, ///< [in] the x/row-coord of the lower left pixel of the source region
int wfY0) ///< [in] the y/col-coord of the lower left pixel of the source region
{
int im_rows = im.cols();
int dest_cols = dest.cols();

int wf_rows = wf.cols();
int src_cols = src.cols();

typedef typename imageT1::Scalar dataT;

dataT * im_data;
dataT * wf_data;
dataT * dest_data;
dataT * src_data;



for(int j =0; j< imYsz; ++j)
{
im_data = &im.data()[imX0 + (imY0+j)*im_rows];
wf_data = &wf.data()[wfX0 + (wfY0+j)*wf_rows];
dest_data = &dest.data()[imX0 + (imY0+j)*dest_cols];
src_data = &src.data()[wfX0 + (wfY0+j)*src_cols];

memcpy( im_data, wf_data, sizeof(dataT)*imXsz);
memcpy( dest_data, src_data, sizeof(dataT)*imXsz);
}
}

/// Extract a pixels from one image and insert them into a second based on a mask
/** Only pixels with a non-zero value in mask are changed in dest to have the value in src. Other pixels are not
* modified.
*/
template< typename imageT1,
typename imageT2,
typename imageT3
>
void extractMaskedPixels( imageT1 & dest, ///< [in/out] the image in which to place the extracted pixels. Must be the same size as src and mask.
const imageT2 & src, ///< [in] the source of the pixels. Must be the same size as mask.
const imageT3 & mask ///< [in] the mask image, where any value other than 0 indicates a pixel to extract. Must be the same size as src.
)
{
if(dest.rows() != src.rows())
{
mxThrowException( mx::err::sizeerr, "mx::imagingUtils::extractMaskedPixels", "dest and src do not have same size (rows)" );
}

if(dest.cols() != src.cols())
{
mxThrowException( mx::err::sizeerr, "mx::imagingUtils::extractMaskedPixels", "dest and src do not have same size (cols)" );
}

if(src.rows() != mask.rows())
{
mxThrowException( mx::err::sizeerr, "mx::imagingUtils::extractMaskedPixels", "src and mask do not have same size (rows)" );
}

if(src.cols() != mask.cols())
{
mxThrowException( mx::err::sizeerr, "mx::imagingUtils::extractMaskedPixels", "src and mask do not have same size (cols)" );
}

for(int cc = 0; cc < dest.cols(); ++cc)
{
for(int rr = 0; rr < dest.rows(); ++rr)
{
if(mask(rr,cc) != 0)
{
dest(rr,cc) = src(rr,cc);
}
}
}
}

template< typename realImageT,
typename complexImageT>
void extractIntensityImage(realImageT & im,
Expand Down
Loading

0 comments on commit 3e1ed58

Please sign in to comment.