Xmipp  v3.23.11-Nereus
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SoftNegativeFilter Class Reference

#include <fourier_filter.h>

Inheritance diagram for SoftNegativeFilter:
Inheritance graph
[legend]
Collaboration diagram for SoftNegativeFilter:
Collaboration graph
[legend]

Public Member Functions

void readParams (XmippProgram *program)
 
void apply (MultidimArray< double > &img)
 
- Public Member Functions inherited from XmippFilter
virtual ~XmippFilter ()
 
virtual void show ()
 

Static Public Member Functions

static void defineParams (XmippProgram *program)
 

Public Attributes

double K
 
FileName fnFSC
 
Image< int > mask
 
double Ts
 

Detailed Description

Definition at line 211 of file fourier_filter.h.

Member Function Documentation

◆ apply()

void SoftNegativeFilter::apply ( MultidimArray< double > &  img)
virtual

Apply the filter to an image or volume

Implements XmippFilter.

Definition at line 879 of file fourier_filter.cpp.

880 {
881  // Invert the mask and measure stddev outside the mask
882  MultidimArray<int> &mMask=mask();
883  mMask.setXmippOrigin();
884  img.setXmippOrigin();
885  double sum=0;
886  double sum2=0;
887  double N=0;
888  auto R2max=(double)((XSIZE(img)/2)*(XSIZE(img)/2));
890  {
891  A3D_ELEM(mMask,k,i,j)=1-A3D_ELEM(mMask,k,i,j);
892  if (A3D_ELEM(mMask,k,i,j))
893  {
894  double R2=i*i+j*j+k*k;
895  if (R2<R2max)
896  {
897  double val=A3D_ELEM(img,k,i,j);
898  sum+=val;
899  sum2+=val*val;
900  N+=1;
901  }
902  }
903  }
904  double avg=sum/N;
905  double stddev=sqrt(sum2/N-avg*avg);
906 
907  // Measure the stddev outside the structure
908  // double avg, stddev;
909  // img.computeAvgStdev_within_binary_mask(mMask,avg,stddev);
910 
911  // Find the too negative values
912  double threshold=-K*stddev;
913  if (avg<0)
914  threshold+=avg;
915  // std::cout << "avg=" << avg << " sigma=" << stddev << " threshold=" << threshold << std::endl;
916  MultidimArray<double> softMask;
917  MultidimArray<double> imgThresholded;
918  softMask.initZeros(mMask);
919  imgThresholded.initZeros(mMask);
921  if (DIRECT_MULTIDIM_ELEM(img,n)>=threshold)
922  {
923  DIRECT_MULTIDIM_ELEM(softMask,n)=1;
924  DIRECT_MULTIDIM_ELEM(imgThresholded,n)=DIRECT_MULTIDIM_ELEM(img,n);
925  }
926  mask.clear(); // Free memory
927 // Image<double> save;
928 // save()=softMask; save.write("PPPsoftmask.vol");
929 
930  FourierFilter filter;
931  filter.FilterBand=filter.FilterShape=FSCPROFILE;
932  filter.fnFSC=fnFSC;
933  filter.sampling_rate=Ts;
934  filter.generateMask(softMask);
935  filter.applyMaskSpace(softMask);
936  filter.applyMaskSpace(imgThresholded);
937  softMask+=1;
938 // save()=softMask; save.write("PPPsoftmaskFiltered.vol");
939 // save()=imgThresholded; save.write("PPPthresholded.vol");
940 
942  {
943  DIRECT_MULTIDIM_ELEM(softMask,n)=CLIP(DIRECT_MULTIDIM_ELEM(softMask,n),0,1);
945  (1-DIRECT_MULTIDIM_ELEM(softMask,n))*DIRECT_MULTIDIM_ELEM(imgThresholded,n);
946  }
947 // save()=softMask; save.write("PPPsoftmaskFilteredClipped.vol");
948 }
void sqrt(Image< double > &op)
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define CLIP(x, x0, xF)
Definition: xmipp_macros.h:260
void threshold(double *phi, unsigned long nvox, double limit)
Definition: lib_vwk.cpp:524
#define A3D_ELEM(V, k, i, j)
double sampling_rate
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
#define FSCPROFILE
void initZeros(const MultidimArray< T1 > &op)
void generateMask(MultidimArray< double > &v)
int * n
void clear()
Definition: xmipp_image.h:144
void applyMaskSpace(MultidimArray< double > &v)

◆ defineParams()

void SoftNegativeFilter::defineParams ( XmippProgram program)
static

Define the parameters for use inside an Xmipp program

Definition at line 861 of file fourier_filter.cpp.

862 {
863  program->addParamsLine("== Soft negative pixels ==");
864  program->addParamsLine(
865  " [ --softnegative <mask_file> <fsc> <Ts=1> <K=2>] : Removes strong negative values inside the mask");
866  program->addParamsLine(" : Ts is the sampling rate in A/pix");
867 }
void addParamsLine(const String &line)

◆ readParams()

void SoftNegativeFilter::readParams ( XmippProgram program)
virtual

Read from program command line

Reimplemented from XmippFilter.

Definition at line 870 of file fourier_filter.cpp.

871 {
872  mask.read(program->getParam("--softnegative",0));
873  fnFSC=program->getParam("--softnegative",1);
874  Ts = program->getDoubleParam("--softnegative",2);
875  K = program->getDoubleParam("--softnegative",3);
876 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

Member Data Documentation

◆ fnFSC

FileName SoftNegativeFilter::fnFSC

Definition at line 215 of file fourier_filter.h.

◆ K

double SoftNegativeFilter::K

Definition at line 214 of file fourier_filter.h.

◆ mask

Image<int> SoftNegativeFilter::mask

Definition at line 216 of file fourier_filter.h.

◆ Ts

double SoftNegativeFilter::Ts

Definition at line 217 of file fourier_filter.h.


The documentation for this class was generated from the following files: