33#include "sparx/processor_sparx.h"
47#include <gsl/gsl_randist.h>
48#include <gsl/gsl_statistics.h>
49#include <gsl/gsl_wavelet.h>
50#include <gsl/gsl_wavelet2d.h>
51#include <gsl/gsl_multimin.h>
53#include <gsl/gsl_fit.h>
57 typedef unsigned int uint;
61 typedef unsigned int uint;
64#ifdef EMAN2_USING_CUDA
72const string SNREvalProcessor::NAME =
"eval.maskedsnr";
73const string AmpweightFourierProcessor::NAME =
"filter.ampweight";
74const string Axis0FourierProcessor::NAME =
"filter.xyaxes0";
75const string ConvolutionProcessor::NAME =
"math.convolution";
76const string BispecSliceProcessor::NAME =
"math.bispectrum.slice";
77const string HarmonicProcessor::NAME =
"math.harmonic";
78const string XGradientProcessor::NAME =
"math.edge.xgradient";
79const string YGradientProcessor::NAME =
"math.edge.ygradient";
80const string ZGradientProcessor::NAME =
"math.edge.zgradient";
81const string ImageDivergenceProcessor::NAME =
"math.divergence";
82const string GradientMagnitudeProcessor::NAME =
"math.gradient.magnitude";
83const string GradientDirectionProcessor::NAME =
"math.gradient.direction";
84const string SDGDProcessor::NAME =
"math.laplacian.sdgd";
85const string LaplacianProcessor::NAME =
"math.laplacian";
86const string LaplacianDirectionProcessor::NAME =
"math.laplacian.direction";
87const string LaplacianMagnitudeProcessor::NAME =
"math.laplacian.magnitude";
88const string Wiener2DAutoAreaProcessor::NAME =
"filter.wiener2dauto";
89const string Wiener2DFourierProcessor::NAME =
"filter.wiener2d";
90const string CtfSimProcessor::NAME =
"math.simulatectf";
91const string LinearRampFourierProcessor::NAME =
"filter.linearfourier";
92const string LoGFourierProcessor::NAME =
"filter.LoG";
93const string DoGFourierProcessor::NAME =
"filter.DoG";
94const string AzSharpProcessor::NAME =
"filter.azimuthal.contrast";
95const string HighpassAutoPeakProcessor::NAME =
"filter.highpass.autopeak";
96const string LinearRampProcessor::NAME =
"eman1.filter.ramp";
97const string AbsoluteValueProcessor::NAME =
"math.absvalue";
98const string CCCSNRProcessor::NAME =
"math.ccc_snr_wiener";
99const string FloorValueProcessor::NAME =
"math.floor";
100const string BooleanProcessor::NAME =
"threshold.notzero";
101const string KmeansSegmentProcessor::NAME =
"segment.kmeans";
102const string GaussSegmentProcessor::NAME =
"segment.gauss";
103const string DistanceSegmentProcessor::NAME =
"segment.distance";
104const string WatershedProcessor::NAME =
"segment.watershed";
105const string SegmentSubunitProcessor::NAME =
"segment.subunit";
106const string RecipCarefullyProcessor::NAME =
"math.reciprocal";
107const string SubtractOptProcessor::NAME =
"math.sub.optimal";
108const string ValuePowProcessor::NAME =
"math.pow";
109const string ValueSquaredProcessor::NAME =
"math.squared";
110const string ValueSqrtProcessor::NAME =
"math.sqrt";
111const string DiscritizeProcessor::NAME =
"threshold.discritize.sigma";
112const string ToZeroProcessor::NAME =
"threshold.belowtozero";
113const string AboveToZeroProcessor::NAME=
"threshold.abovetozero";
114const string OutlierProcessor::NAME=
"threshold.outlier.localmean";
115const string Rotate180Processor::NAME =
"math.rotate.180";
116const string TransformProcessor::NAME =
"xform";
117const string IntTranslateProcessor::NAME =
"xform.translate.int";
118const string ScaleTransformProcessor::NAME =
"xform.scale";
119const string ApplySymProcessor::NAME =
"xform.applysym";
120const string ClampingProcessor::NAME =
"threshold.clampminmax";
121const string RangeZeroProcessor::NAME =
"threshold.rangetozero";
122const string NSigmaClampingProcessor::NAME =
"threshold.clampminmax.nsigma";
123const string ToMinvalProcessor::NAME =
"threshold.belowtominval";
124const string CutToZeroProcessor::NAME =
"threshold.belowtozero_cut";
125const string BinarizeProcessor::NAME =
"threshold.binary";
127const string BinarizeFourierProcessor::NAME =
"threshold.binary.fourier";
128const string CollapseProcessor::NAME =
"threshold.compress";
129const string LinearXformProcessor::NAME =
"math.linear";
130const string ExpProcessor::NAME =
"math.exp";
131const string FiniteProcessor::NAME =
"math.finite";
132const string RangeThresholdProcessor::NAME =
"threshold.binaryrange";
133const string SigmaProcessor::NAME =
"math.sigma";
134const string LogProcessor::NAME =
"math.log";
135const string MaskSharpProcessor::NAME =
"mask.sharp";
136const string MaskSoftProcessor::NAME =
"mask.soft";
137const string MaskEdgeMeanProcessor::NAME =
"mask.ringmean";
138const string MaskNoiseProcessor::NAME =
"mask.noise";
139const string MaskGaussProcessor::NAME =
"mask.gaussian";
140const string MaskAzProcessor::NAME =
"mask.cylinder";
141const string MaskGaussNonuniformProcessor::NAME =
"mask.gaussian.nonuniform";
142const string MaskGaussInvProcessor::NAME =
"math.gausskernelfix";
143const string GridKernelFixProcessor::NAME =
"math.gridkernelfix";
144const string LinearPyramidProcessor::NAME =
"math.linearpyramid";
145const string SetBitsProcessor::NAME =
"math.setbits";
146const string MakeRadiusSquaredProcessor::NAME =
"math.toradiussqr";
147const string MakeRadiusProcessor::NAME =
"math.toradius";
148const string ComplexNormPixel::NAME =
"complex.normpixels";
149const string ZeroConstantProcessor::NAME =
"mask.contract";
150const string BoxMedianProcessor::NAME =
"eman1.filter.median";
151const string BoxSigmaProcessor::NAME =
"math.localsigma";
152const string NonConvexProcessor::NAME =
"math.nonconvex";
153const string BoxMaxProcessor::NAME =
"math.localmax";
154const string LocalMinAbsProcessor::NAME =
"math.localminabs";
155const string MinusPeakProcessor::NAME =
"math.submax";
156const string PeakOnlyProcessor::NAME =
"mask.onlypeaks";
157const string DiffBlockProcessor::NAME =
"eman1.filter.blockrange";
158const string CutoffBlockProcessor::NAME =
"eman1.filter.blockcutoff";
159const string MaxShrinkProcessor::NAME =
"math.maxshrink";
160const string MinShrinkProcessor::NAME =
"math.minshrink";
161const string MeanShrinkProcessor::NAME =
"math.meanshrink";
162const string MedianShrinkProcessor::NAME =
"math.medianshrink";
163const string FFTResampleProcessor::NAME =
"math.fft.resample";
164const string GradientRemoverProcessor::NAME =
"math.lineargradientfix";
165const string GradientPlaneRemoverProcessor::NAME =
"filter.gradientPlaneRemover";
166const string FlattenBackgroundProcessor::NAME =
"filter.flattenbackground";
167const string RampProcessor::NAME =
"filter.ramp";
168const string VerticalStripeProcessor::NAME =
"math.verticalstripefix";
169const string RealToFFTProcessor::NAME =
"math.realtofft";
170const string SigmaZeroEdgeProcessor::NAME =
"mask.zeroedgefill";
171const string WedgeFillProcessor::NAME =
"mask.wedgefill";
172const string FFTPeakProcessor::NAME =
"mask.fft.peak";
173const string FFTConeProcessor::NAME =
"mask.fft.cone";
174const string FFTWedgeProcessor::NAME =
"mask.fft.wedge";
175const string BeamstopProcessor::NAME =
"mask.beamstop";
176const string MeanZeroEdgeProcessor::NAME =
"mask.dampedzeroedgefill";
177const string AverageXProcessor::NAME =
"math.averageovery";
178const string DecayEdgeProcessor::NAME =
"mask.decayedge2d";
179const string ZeroEdgeRowProcessor::NAME =
"mask.zeroedge2d";
180const string ZeroEdgePlaneProcessor::NAME =
"mask.zeroedge3d";
181const string BilateralProcessor::NAME =
"filter.bilateral";
182const string NormalizeUnitProcessor::NAME =
"normalize.unitlen";
183const string NormalizeUnitSumProcessor::NAME =
"normalize.unitsum";
184const string NormalizeStdProcessor::NAME =
"normalize";
185const string NormalizeMaskProcessor::NAME =
"normalize.mask";
186const string NormalizeRampNormVar::NAME =
"normalize.ramp.normvar";
187const string NormalizeByMassProcessor::NAME =
"normalize.bymass";
188const string NormalizeEdgeMeanProcessor::NAME =
"normalize.edgemean";
189const string NormalizeCircleMeanProcessor::NAME =
"normalize.circlemean";
190const string NormalizeLREdgeMeanProcessor::NAME =
"normalize.lredge";
191const string NormalizeHistPeakProcessor::NAME =
"normalize.histpeak";
192const string NormalizeMaxMinProcessor::NAME =
"normalize.maxmin";
193const string NormalizeRowProcessor::NAME =
"normalize.rows";
194const string NormalizeToLeastSquareProcessor::NAME =
"normalize.toimage";
195const string RotationalAverageProcessor::NAME =
"math.rotationalaverage";
196const string RotationalSubstractProcessor::NAME =
"math.rotationalsubtract";
197const string TransposeProcessor::NAME =
"xform.transpose";
198const string FlipProcessor::NAME =
"xform.flip";
199const string AddNoiseProcessor::NAME =
"math.addnoise";
200const string AddSigmaNoiseProcessor::NAME =
"math.addsignoise";
201const string AddRandomNoiseProcessor::NAME =
"math.addspectralnoise";
202const string FourierToCornerProcessor::NAME =
"xform.fourierorigin.tocorner";
203const string FourierToCenterProcessor::NAME =
"xform.fourierorigin.tocenter";
204const string PhaseToCenterProcessor::NAME =
"xform.phaseorigin.tocenter";
205const string PhaseToCornerProcessor::NAME =
"xform.phaseorigin.tocorner";
206const string AutoMask2DProcessor::NAME =
"mask.auto2d";
207const string AutoMaskAsymUnit::NAME =
"mask.asymunit";
208const string AutoMask3DProcessor::NAME =
"mask.auto3d.thresh";
209const string AutoMask3D2Processor::NAME =
"mask.auto3d";
210const string AutoMaskDustProcessor::NAME =
"mask.dust3d";
211const string AddMaskShellProcessor::NAME =
"mask.addshells";
212const string IterMultiMaskProcessor::NAME =
"mask.addshells.multilevel";
213const string IterBinMaskProcessor::NAME =
"mask.addshells.gauss";
214const string PhaseToMassCenterProcessor::NAME =
"xform.phasecenterofmass";
215const string ToMassCenterProcessor::NAME =
"xform.centerofmass";
216const string ToCenterProcessor::NAME =
"xform.center";
217const string ACFCenterProcessor::NAME =
"xform.centeracf";
218const string CTFCorrProcessor::NAME =
"filter.ctfcorr.simple";
219const string SNRProcessor::NAME =
"eman1.filter.snr";
220const string FileFourierProcessor::NAME =
"eman1.filter.byfile";
221const string FSCFourierProcessor::NAME =
"filter.wiener.byfsc";
222const string SymSearchProcessor::NAME =
"misc.symsearch";
223const string MaskPackProcessor::NAME =
"misc.mask.pack";
224const string LocalNormProcessor::NAME =
"normalize.local";
225const string StripeXYProcessor::NAME =
"math.xystripefix";
226const string BadLineXYProcessor::NAME =
"math.xybadlines";
227const string IndexMaskFileProcessor::NAME =
"mask.fromfile";
229const string PaintProcessor::NAME =
"mask.paint";
230const string DirectionalSumProcessor::NAME =
"misc.directional_sum";
233const string MaxPixelOperator::NAME =
"math.max";
234const string MinPixelOperator::NAME =
"math.min";
235const string MatchSFProcessor::NAME =
"filter.matchto";
236const string SetSFProcessor::NAME =
"filter.setstrucfac";
237const string SetIsoPowProcessor::NAME =
"filter.setisotropicpow";
238const string SmartMaskProcessor::NAME =
"mask.smart";
239const string TestImagePureGaussian::NAME =
"testimage.puregaussian";
240const string TestImageFourierGaussianBand::NAME =
"testimage.fourier.gaussianband";
241const string TestImageFourierNoiseGaussian::NAME =
"testimage.noise.fourier.gaussian";
242const string TestImageFourierNoiseProfile::NAME =
"testimage.noise.fourier.profile";
243const string CTFSNRWeightProcessor::NAME =
"ctf.snr.weight";
244const string TestImageLineWave::NAME =
"testimage.linewave";
245const string TestTomoImage::NAME =
"testimage.tomo.objects";
246const string TestImageGradient::NAME =
"testimage.gradient";
247const string TestImageAxes::NAME =
"testimage.axes";
248const string TestImageGaussian::NAME =
"testimage.gaussian";
249const string TestImageScurve::NAME =
"testimage.scurve";
250const string TestImageSphericalWave::NAME =
"testimage.sphericalwave";
251const string TestImageSinewave::NAME =
"testimage.sinewave";
252const string TestImageSinewaveCircular::NAME =
"testimage.sinewave.circular";
253const string TestImageSquarecube::NAME =
"testimage.squarecube";
254const string TestImageEllipse::NAME =
"testimage.ellipsoid";
255const string TestImageHollowEllipse::NAME =
"testimage.ellipsoid.hollow";
256const string TestImageCirclesphere::NAME =
"testimage.circlesphere";
257const string TestImageNoiseUniformRand::NAME =
"testimage.noise.uniform.rand";
258const string TestImageNoiseGauss::NAME =
"testimage.noise.gauss";
259const string TestImageCylinder::NAME =
"testimage.cylinder";
260const string TestImageDisc::NAME =
"testimage.disc";
261const string CCDNormProcessor::NAME =
"filter.ccdnorm";
262const string WaveletProcessor::NAME =
"basis.wavelet";
263const string EnhanceProcessor::NAME =
"filter.enhance";
264const string TomoTiltEdgeMaskProcessor::NAME =
"tomo.tiltedgemask";
265const string TomoTiltAngleWeightProcessor::NAME =
"tomo.tiltangleweight";
266const string FFTProcessor::NAME =
"basis.fft";
267const string RadialProcessor::NAME =
"mask.radialprofile";
268const string HistogramBin::NAME =
"histogram.bin";
269const string ModelEMCylinderProcessor::NAME =
"math.model_em_cylinder";
270const string ApplyPolynomialProfileToHelix::NAME =
"math.poly_radial_profile";
271const string BinarySkeletonizerProcessor::NAME=
"gorgon.binary_skel";
272const string MirrorProcessor::NAME =
"xform.mirror";
273const string ReverseProcessor::NAME =
"xform.reverse";
274const string NewLowpassTopHatProcessor::NAME =
"filter.lowpass.tophat";
275const string NewHighpassTopHatProcessor::NAME =
"filter.highpass.tophat";
276const string NewBandpassTopHatProcessor::NAME =
"filter.bandpass.tophat";
277const string NewHomomorphicTopHatProcessor::NAME =
"filter.homomorphic.tophat";
278const string NewLowpassGaussProcessor::NAME =
"filter.lowpass.gauss";
279const string LowpassAutoBProcessor::NAME=
"filter.lowpass.autob";
280const string NewHighpassGaussProcessor::NAME =
"filter.highpass.gauss";
281const string NewBandpassGaussProcessor::NAME =
"filter.bandpass.gauss";
282const string NewHomomorphicGaussProcessor::NAME =
"filter.homomorphic.gauss";
283const string NewInverseGaussProcessor::NAME =
"filter.gaussinverse";
284const string GaussZFourierProcessor::NAME =
"filter.lowpass.gaussz";
285const string SHIFTProcessor::NAME =
"filter.shift";
286const string InverseKaiserI0Processor::NAME =
"filter.kaiser_io_inverse";
287const string InverseKaiserSinhProcessor::NAME =
"filter.kaisersinhinverse";
288const string NewRadialTableProcessor::NAME =
"filter.radialtable";
289const string LowpassRandomPhaseProcessor::NAME =
"filter.lowpass.randomphase";
290const string NewLowpassButterworthProcessor::NAME =
"filter.lowpass.butterworth";
291const string NewHighpassButterworthProcessor::NAME =
"filter.highpass.butterworth";
292const string NewHomomorphicButterworthProcessor::NAME =
"filter.homomorphic.butterworth";
293const string NewLowpassTanhProcessor::NAME =
"filter.lowpass.tanh";
294const string NewHighpassTanhProcessor::NAME =
"filter.highpass.tanh";
295const string NewHomomorphicTanhProcessor::NAME =
"filter.homomorphic.tanh";
296const string NewBandpassTanhProcessor::NAME =
"filter.bandpass.tanh";
297const string CTF_Processor::NAME =
"filter.CTF_";
298const string ConvolutionKernelProcessor::NAME =
"filter.convolution.kernel";
299const string RotateInFSProcessor::NAME =
"rotateinfs";
300const string CircularAverageBinarizeProcessor::NAME =
"threshold.binary.circularmean";
301const string ObjDensityProcessor::NAME =
"morph.object.density";
302const string ObjLabelProcessor::NAME =
"morph.object.label";
303const string BwThinningProcessor::NAME =
"morph.thin";
304const string BwMajorityProcessor::NAME =
"morph.majority";
305const string PruneSkeletonProcessor::NAME =
"morph.prune";
306const string ManhattanDistanceProcessor::NAME =
"math.distance.manhattan";
307const string BinaryDilationProcessor::NAME =
"morph.dilate.binary";
308const string BinaryErosionProcessor::NAME =
"morph.erode.binary";
309const string BinaryOpeningProcessor::NAME =
"morph.open.binary";
310const string BinaryClosingProcessor::NAME =
"morph.close.binary";
311const string BinaryMorphGradientProcessor::NAME =
"morph.gradient.binary";
312const string BinaryExternalGradientProcessor::NAME =
"morph.ext_grad.binary";
313const string BinaryInternalGradientProcessor::NAME =
"morph.int_grad.binary";
314const string BinaryTopHatProcessor::NAME =
"morph.tophat.binary";
315const string BinaryBlackHatProcessor::NAME =
"morph.blackhat.binary";
316const string GrowSkeletonProcessor::NAME =
"morph.grow";
317const string FixSignProcessor::NAME =
"math.fixmode";
318const string ZThicknessProcessor::NAME =
"misc.zthick";
319const string ReplaceValuefromListProcessor::NAME =
"misc.colorlabel";
320const string PolyMaskProcessor::NAME =
"mask.poly";
321const string AmpMultProcessor::NAME =
"math.multamplitude";
335 force_add<HighpassAutoPeakProcessor>();
336 force_add<LinearRampFourierProcessor>();
337 force_add<LoGFourierProcessor>();
338 force_add<DoGFourierProcessor>();
340 force_add<FixSignProcessor>();
342 force_add<AmpweightFourierProcessor>();
343 force_add<Axis0FourierProcessor>();
344 force_add<Wiener2DFourierProcessor>();
345 force_add<LowpassAutoBProcessor>();
346 force_add<CtfSimProcessor>();
348 force_add<LinearPyramidProcessor>();
349 force_add<LinearRampProcessor>();
350 force_add<AbsoluteValueProcessor>();
351 force_add<FloorValueProcessor>();
352 force_add<BooleanProcessor>();
353 force_add<KmeansSegmentProcessor>();
354 force_add<GaussSegmentProcessor>();
355 force_add<SegmentSubunitProcessor>();
356 force_add<DistanceSegmentProcessor>();
357 force_add<ValuePowProcessor>();
358 force_add<ValueSquaredProcessor>();
359 force_add<ValueSqrtProcessor>();
360 force_add<DiscritizeProcessor>();
361 force_add<Rotate180Processor>();
362 force_add<TransformProcessor>();
363 force_add<ScaleTransformProcessor>();
364 force_add<ApplySymProcessor>();
365 force_add<IntTranslateProcessor>();
366 force_add<RecipCarefullyProcessor>();
367 force_add<SubtractOptProcessor>();
369 force_add<ClampingProcessor>();
370 force_add<NSigmaClampingProcessor>();
372 force_add<ToZeroProcessor>();
373 force_add<RangeZeroProcessor>();
374 force_add<AboveToZeroProcessor>();
375 force_add<OutlierProcessor>();
376 force_add<ToMinvalProcessor>();
377 force_add<CutToZeroProcessor>();
378 force_add<BinarizeProcessor>();
380 force_add<BinarizeFourierProcessor>();
381 force_add<CollapseProcessor>();
382 force_add<LinearXformProcessor>();
383 force_add<SetBitsProcessor>();
385 force_add<CCCSNRProcessor>();
386 force_add<ExpProcessor>();
387 force_add<RangeThresholdProcessor>();
388 force_add<SigmaProcessor>();
389 force_add<LogProcessor>();
390 force_add<FiniteProcessor>();
392 force_add< BinaryOperateProcessor<MaxPixelOperator> >();
393 force_add< BinaryOperateProcessor<MinPixelOperator> >();
395 force_add<PaintProcessor>();
396 force_add<WatershedProcessor>();
397 force_add<MaskSharpProcessor>();
398 force_add<MaskSoftProcessor>();
399 force_add<MaskEdgeMeanProcessor>();
400 force_add<MaskNoiseProcessor>();
401 force_add<MaskGaussProcessor>();
402 force_add<MaskGaussNonuniformProcessor>();
403 force_add<MaskGaussInvProcessor>();
404 force_add<GridKernelFixProcessor>();
405 force_add<MaskAzProcessor>();
407 force_add<MaxShrinkProcessor>();
408 force_add<MinShrinkProcessor>();
409 force_add<MeanShrinkProcessor>();
410 force_add<MedianShrinkProcessor>();
411 force_add<FFTResampleProcessor>();
412 force_add<NonConvexProcessor>();
414 force_add<MakeRadiusSquaredProcessor>();
415 force_add<MakeRadiusProcessor>();
417 force_add<ComplexNormPixel>();
419 force_add<LaplacianProcessor>();
422 force_add<BoxMedianProcessor>();
423 force_add<BoxSigmaProcessor>();
424 force_add<BoxMaxProcessor>();
425 force_add<LocalMinAbsProcessor>();
427 force_add<MinusPeakProcessor>();
428 force_add<PeakOnlyProcessor>();
429 force_add<DiffBlockProcessor>();
431 force_add<CutoffBlockProcessor>();
433 force_add<GradientPlaneRemoverProcessor>();
434 force_add<FlattenBackgroundProcessor>();
435 force_add<VerticalStripeProcessor>();
436 force_add<RealToFFTProcessor>();
437 force_add<SigmaZeroEdgeProcessor>();
438 force_add<WedgeFillProcessor>();
439 force_add<FFTPeakProcessor>();
440 force_add<FFTConeProcessor>();
441 force_add<FFTWedgeProcessor>();
442 force_add<RampProcessor>();
444 force_add<BeamstopProcessor>();
445 force_add<MeanZeroEdgeProcessor>();
446 force_add<AverageXProcessor>();
447 force_add<DecayEdgeProcessor>();
448 force_add<ZeroEdgeRowProcessor>();
449 force_add<ZeroEdgePlaneProcessor>();
451 force_add<BilateralProcessor>();
453 force_add<ConvolutionProcessor>();
454 force_add<BispecSliceProcessor>();
455 force_add<HarmonicProcessor>();
457 force_add<NormalizeStdProcessor>();
458 force_add<NormalizeHistPeakProcessor>();
459 force_add<NormalizeUnitProcessor>();
460 force_add<NormalizeUnitSumProcessor>();
461 force_add<NormalizeMaskProcessor>();
462 force_add<NormalizeEdgeMeanProcessor>();
463 force_add<NormalizeCircleMeanProcessor>();
464 force_add<NormalizeLREdgeMeanProcessor>();
465 force_add<NormalizeMaxMinProcessor>();
466 force_add<NormalizeByMassProcessor>();
467 force_add<NormalizeRowProcessor>();
468 force_add<NormalizeRampNormVar>();
470 force_add<HistogramBin>();
472 force_add<NormalizeToLeastSquareProcessor>();
474 force_add<RotationalAverageProcessor>();
475 force_add<RotationalSubstractProcessor>();
476 force_add<FlipProcessor>();
477 force_add<TransposeProcessor>();
478 force_add<MirrorProcessor>();
479 force_add<ReverseProcessor>();
481 force_add<AddNoiseProcessor>();
482 force_add<AddSigmaNoiseProcessor>();
483 force_add<AddRandomNoiseProcessor>();
485 force_add<PhaseToCenterProcessor>();
486 force_add<PhaseToCornerProcessor>();
487 force_add<FourierToCenterProcessor>();
488 force_add<FourierToCornerProcessor>();
489 force_add<AutoMask2DProcessor>();
490 force_add<AutoMask3DProcessor>();
491 force_add<AutoMask3D2Processor>();
492 force_add<AutoMaskDustProcessor>();
493 force_add<AddMaskShellProcessor>();
494 force_add<IterMultiMaskProcessor>();
495 force_add<IterBinMaskProcessor>();
496 force_add<AutoMaskAsymUnit>();
498 force_add<CTFSNRWeightProcessor>();
500 force_add<ToMassCenterProcessor>();
501 force_add<ToCenterProcessor>();
502 force_add<PhaseToMassCenterProcessor>();
503 force_add<ACFCenterProcessor>();
505 force_add<CTFCorrProcessor>();
506 force_add<FSCFourierProcessor>();
508 force_add<XGradientProcessor>();
509 force_add<YGradientProcessor>();
510 force_add<ZGradientProcessor>();
512 force_add<ImageDivergenceProcessor>();
513 force_add<GradientMagnitudeProcessor>();
514 force_add<GradientDirectionProcessor>();
515 force_add<LaplacianMagnitudeProcessor>();
516 force_add<LaplacianDirectionProcessor>();
517 force_add<SDGDProcessor>();
521 force_add<SymSearchProcessor>();
522 force_add<MaskPackProcessor>();
523 force_add<StripeXYProcessor>();
524 force_add<BadLineXYProcessor>();
525 force_add<LocalNormProcessor>();
527 force_add<IndexMaskFileProcessor>();
529 force_add<SetIsoPowProcessor>();
530 force_add<SetSFProcessor>();
531 force_add<MatchSFProcessor>();
533 force_add<SmartMaskProcessor>();
535 force_add<TestImageGaussian>();
536 force_add<TestImagePureGaussian>();
537 force_add<TestImageSinewave>();
538 force_add<TestImageSphericalWave>();
539 force_add<TestImageSinewaveCircular>();
540 force_add<TestImageSquarecube>();
541 force_add<TestImageCirclesphere>();
542 force_add<TestImageAxes>();
543 force_add<TestImageNoiseUniformRand>();
544 force_add<TestImageNoiseGauss>();
545 force_add<TestImageScurve>();
546 force_add<TestImageCylinder>();
547 force_add<TestImageDisc>();
548 force_add<TestImageGradient>();
549 force_add<TestTomoImage>();
550 force_add<TestImageLineWave>();
551 force_add<TestImageEllipse>();
552 force_add<TestImageHollowEllipse>();
553 force_add<TestImageFourierGaussianBand>();
554 force_add<TestImageFourierNoiseGaussian>();
555 force_add<TestImageFourierNoiseProfile>();
557 force_add<TomoTiltEdgeMaskProcessor>();
558 force_add<TomoTiltAngleWeightProcessor>();
560 force_add<NewLowpassTopHatProcessor>();
561 force_add<NewHighpassTopHatProcessor>();
562 force_add<NewBandpassTopHatProcessor>();
563 force_add<NewHomomorphicTopHatProcessor>();
564 force_add<NewLowpassGaussProcessor>();
565 force_add<NewHighpassGaussProcessor>();
566 force_add<NewBandpassGaussProcessor>();
567 force_add<NewHomomorphicGaussProcessor>();
568 force_add<NewInverseGaussProcessor>();
569 force_add<GaussZFourierProcessor>();
570 force_add<LowpassRandomPhaseProcessor>();
571 force_add<NewLowpassButterworthProcessor>();
572 force_add<NewHighpassButterworthProcessor>();
573 force_add<NewHomomorphicButterworthProcessor>();
574 force_add<NewLowpassTanhProcessor>();
575 force_add<NewHighpassTanhProcessor>();
576 force_add<NewBandpassTanhProcessor>();
577 force_add<NewHomomorphicTanhProcessor>();
578 force_add<NewRadialTableProcessor>();
579 force_add<InverseKaiserI0Processor>();
580 force_add<InverseKaiserSinhProcessor>();
581 force_add<CCDNormProcessor>();
582 force_add<CTF_Processor>();
583 force_add<SHIFTProcessor>();
586 force_add<EnhanceProcessor>();
587 force_add<FFTProcessor>();
588 force_add<RadialProcessor>();
590 force_add<DirectionalSumProcessor>();
591 force_add<ConvolutionKernelProcessor>();
594 force_add<ModelEMCylinderProcessor>();
595 force_add<ApplyPolynomialProfileToHelix>();
596 force_add<BinarySkeletonizerProcessor>();
597 force_add<RotateInFSProcessor>();
598 force_add<CircularAverageBinarizeProcessor>();
599 force_add<ObjDensityProcessor>();
600 force_add<ObjLabelProcessor>();
601 force_add<BwThinningProcessor>();
602 force_add<BwMajorityProcessor>();
603 force_add<PruneSkeletonProcessor>();
604 force_add<GrowSkeletonProcessor>();
606 force_add<ManhattanDistanceProcessor>();
607 force_add<BinaryDilationProcessor>();
608 force_add<BinaryErosionProcessor>();
609 force_add<BinaryClosingProcessor>();
610 force_add<BinaryOpeningProcessor>();
611 force_add<BinaryMorphGradientProcessor>();
612 force_add<BinaryExternalGradientProcessor>();
613 force_add<BinaryInternalGradientProcessor>();
614 force_add<BinaryTopHatProcessor>();
615 force_add<BinaryBlackHatProcessor>();
616 force_add<ZThicknessProcessor>();
617 force_add<ReplaceValuefromListProcessor>();
618 force_add<PolyMaskProcessor>();
619 force_add<AmpMultProcessor>();
629void FiniteProcessor::process_pixel(
float *
x)
const
639 EMData * result = image->copy();
654 if (image->is_complex()) {
655 (*image) *= *processor_image;
658 EMData *fft = image->do_fft();
659 (*fft) *= (*processor_image);
660 EMData *ift = fft->do_ift();
662 float *data = image->get_data();
664 float *ift_data = ift->get_data();
687#define FFTRADIALOVERSAMPLE 4
698 float step=0.5f/array_size;
701 vector < float >yarray(array_size);
705 if (image->is_complex()) {
709 EMData *fft = image->do_fft();
711 EMData *ift = fft->do_ift();
713 memcpy(image->get_data(),ift->get_data(),ift->get_xsize()*ift->get_ysize()*ift->get_zsize()*
sizeof(
float));
729 if (return_radial) image->set_attr(
"filter_curve",yarray);
752 if (image->get_zsize()>1) cornerscale=
sqrt(3.0);
753 else cornerscale=
sqrt(2.0);
755 if (image->is_complex()) {
756 vector <float>yarray = image->
calc_radial_dist(floor(image->get_ysize()*cornerscale/2),0,1.0,1);
759 if (return_radial) image->set_attr(
"filter_curve",yarray);
762 EMData *fft = image->do_fft();
763 vector <float>yarray = fft->
calc_radial_dist((
int)floor(fft->get_ysize()*cornerscale/2.0),0,1.0,1);
768 EMData *ift = fft->do_ift();
770 memcpy(image->get_data(),ift->get_data(),ift->get_xsize()*ift->get_ysize()*ift->get_zsize()*
sizeof(
float));
771 if (return_radial) image->set_attr(
"filter_curve",yarray);
789 if ((
float)mask->get_attr(
"mean_nonzero")!=1.0f)
throw InvalidParameterException(
"MaskPackProcessor requires a binary mask");
791 int n_nz=(int)mask->get_attr(
"square_sum");
795 ret =
new EMData(mask->get_xsize(),mask->get_ysize(),mask->get_zsize());
799 for (
size_t i=0; i<ret->get_size(); i++) {
800 if (mask->get_value_at_index(i)) ret->set_value_at_index(i,image->get_value_at_index(ix++));
804 ret =
new EMData(n_nz,1,1);
808 for (
size_t i=0; i<image->get_size(); i++) {
809 if (mask->get_value_at_index(i)) ret->set_value_at_index(ix++,image->get_value_at_index(i));
825 string mode=(string)
params[
"mode"];
827 int nx = image->get_xsize();
828 int ny = image->get_ysize();
829 int nz = image->get_zsize();
835 if (nx&1) fft->set_fftpad(1);
839 if (mode==
"gridding_5") {
840 for (
int z=-2; z<3; z++) {
841 for (
int y=-2;
y<3;
y++) {
842 for (
int x=0;
x<3;
x++) {
848 else if (mode==
"gridding_7") {
849 for (
int z=-3; z<4; z++) {
850 for (
int y=-3;
y<4;
y++) {
851 for (
int x=0;
x<4;
x++) {
857 else throw InvalidParameterException(
"Gridding kernel correction of unknown mode, only gridding_5 or gridding_7 allowed");
860 real->process_inplace(
"xform.phaseorigin.tocenter");
861 real->mult(2.0f/(
float)
real->get_attr(
"maximum"));
862 real->process_inplace(
"math.reciprocal");
863 real->process_inplace(
"threshold.clampminmax",
Dict(
"minval",-4.0f,
"maxval",4.0f));
883 if (image->is_complex()) fft=image;
884 else EMData *fft = image->do_fft();
886 int nx=fft->get_xsize();
887 int ny=fft->get_ysize();
888 int nz=fft->get_zsize();
894 if (image->is_complex()) {
895 EMData *ift = fft->do_ift();
897 memcpy(image->get_data(),ift->get_data(),ift->get_xsize()*ift->get_ysize()*ift->get_zsize()*
sizeof(
float));
911 if (!image->is_complex()) fft = image->do_fft();
914 int nx=fft->get_xsize();
915 int ny=fft->get_ysize();
916 int nz=fft->get_zsize();
924 for (
int i=0; i<nx/2; i++) thr[i]=thresh_sigma*
sqrt(thr[i]-amp[i]*amp[i])+amp[i];
927 for (
int z=-nz/2; z<nz/2; z++) {
928 for (
int y=-ny/2;
y<ny/2;
y++) {
929 for (
int x=0;
x<nx/2;
x++) {
932 if (r>=nx/2)
continue;
933 complex<float> v=fft->get_complex_at(
x,
y,z);
934 float va=std::abs(v);
939 fft->set_complex_at(
x,
y,z,v);
941 else fft->set_complex_at(
x,
y,z,0.0);
948 fft->set_complex_at(
x,
y,z,v);
950 else fft->set_complex_at(
x,
y,z,0.0);
958 for (
int y=-ny/2;
y<ny/2;
y++) {
959 for (
int x=0;
x<nx/2;
x++) {
961 if (r>=nx/2)
continue;
962 complex<float> v=fft->get_complex_at(
x,
y);
963 float va=std::abs(v);
968 fft->set_complex_at(
x,
y,v);
970 else fft->set_complex_at(
x,
y,0.0);
977 fft->set_complex_at(
x,
y,v);
979 else fft->set_complex_at(
x,
y,0.0);
987 EMData *ift=fft->do_ift();
988 memcpy(image->get_data(),ift->get_data(),(nx-2)*ny*nz*
sizeof(
float));
1002 if (!image->is_complex()) fft = image->do_fft();
1006 int nx=fft->get_xsize();
1007 int ny=fft->get_ysize();
1008 int nz=fft->get_zsize();
1014 for (
int z=-nz/2; z<nz/2; z++) {
1015 for (
int y=-ny/2;
y<ny/2;
y++) {
1016 for (
int x=0;
x<nx/2;
x++) {
1018 if (
x!=0 ||
y!=0) ang=90.0-atan(fabs(
float(z)/nz)/hypot(
float(
x)/nx,
float(
y)/ny))*180.0/M_PI;
1020 fft->set_complex_at(
x,
y,z,0.0f);
1026 EMData *ift=fft->do_ift();
1027 memcpy(image->get_data(),ift->get_data(),(nx-2)*ny*nz*
sizeof(
float));
1041 if (!image->is_complex()) fft = image->do_fft();
1045 int nx=fft->get_xsize();
1046 int ny=fft->get_ysize();
1047 int nz=fft->get_zsize();
1054 for (
int z=-nz/2; z<nz/2; z++) {
1055 for (
int y=-ny/2;
y<ny/2;
y++) {
1056 for (
int x=0;
x<nx/2;
x++) {
1058 if (z!=0) ang=atan((
float(
y)/ny)/fabs(
float(z)/nz))*180.0/M_PI;
1059 if (ang<anglemin||ang>anglemax ||
Util::hypot3(
x,
y,z)<rmin)
continue;
1060 fft->set_complex_at(
x,
y,z,0.0f);
1066 EMData *ift=fft->do_ift();
1067 memcpy(image->get_data(),ift->get_data(),(nx-2)*ny*nz*
sizeof(
float));
1080 if (!image->is_complex())
throw ImageFormatException(
"WedgeFillProcessor: target image must be complex");
1085 if (source && !source->is_complex())
throw ImageFormatException(
"WedgeFillProcessor: fillsource must be complex");
1086 if (image->get_xsize()!=source->get_xsize()||image->get_ysize()!=source->get_ysize()||image->get_zsize()!=source->get_zsize())
throw ImageFormatException(
"WedgeFillProcessor: image/fill size mismatch");
1088 int nx=image->get_xsize();
1089 int ny=image->get_ysize();
1090 int nz=image->get_zsize();
1092 bool dosigma = 1 ? thresh_sigma>0.0 : 0;
1095 bool dotilt = 1 ? maxtilt <90.0 : 0;
1096 maxtilt*=M_PI/180.0;
1098 vector<float> sigmaimg;
1101 for (
int i=0; i<nx/2; i++) sigmaimg[i]*=sigmaimg[i]*thresh_sigma;
1104 vector<int> realpixel(nx/2);
1105 for (
int i=0; i<nx/2; i++) realpixel[i]=0;
1107 for (
int z=0; z<nz; z++) {
1108 for (
int y=0;
y<ny;
y++) {
1109 for (
int x=0;
x<nx;
x+=2) {
1115 if (dotilt) tilt=atan2((
float)(z<nz/2?z:nz-z),(
float)(
x/2));
1117 float v1r=image->get_value_at(
x,
y,z);
1118 float v1i=image->get_value_at(
x+1,
y,z);
1121 if ((!dosigma || v1>sigmaimg[r]) && r<nx/2 && (!dotilt || fabs(tilt)<maxtilt)){
1127 image->set_value_at_fast(
x,
y,z,0);
1128 image->set_value_at_fast(
x+1,
y,z,0);
1131 image->set_value_at_fast(
x,
y,z,source->get_value_at(
x,
y,z));
1132 image->set_value_at_fast(
x+1,
y,z,source->get_value_at(
x+1,
y,z));
1138 image->set_attr(
"real_pixels", realpixel);
1144 float apix=(float)image->get_attr(
"apix_x");
1145 int verbose=(int)
params[
"verbose"];
1149 float ds=1.0f/(apix*image->get_ysize());
1150 unsigned int start=(int)floor(1.0/(15.0*ds));
1151 unsigned int end=radial_mask.size()-2;
1152 if (noisecutoff>0) end=(int)floor(noisecutoff/ds);
1153 if (end>radial_mask.size()-2) {
1154 if (verbose) printf(
"WARNING: specified noisecutoff too close to Nyquist, reset !");
1155 end=radial_mask.size()-2;
1158 printf(
"WARNING: noise cutoff too close to 15 A ! Results will not be good...");
1164 printf(
"Autob -> %d - %d ds=%g apix=%g rdlmsk=%d\n",start,end,ds,apix,
int(radial_mask.size()));
1165 out=fopen(
"fitplot.txt",
"w");
1167 int N=(radial_mask.size()-start-2);
1168 float *
x=(
float *)malloc(N*
sizeof(
float));
1169 float *
y=(
float *)malloc(N*
sizeof(
float));
1170 float *dy=(
float *)malloc(N*
sizeof(
float));
1171 for (
unsigned int i=start; i<radial_mask.size()-2; i++ ) {
1172 x[i-start]=ds*ds*i*i;
1173 if (radial_mask[i]>0)
y[i-start]=
log(radial_mask[i]);
1174 else if (i>start)
y[i-start]=
y[i-start-1];
1175 else y[i-start]=0.0;
1176 if (i>start &&i<radial_mask.size()-3) dy[i-start]=
y[i-start]-
y[i-start-1];
1177 if (out) fprintf(out,
"%f\t%f\n",
x[i-start],
y[i-start]);
1179 if (out) fclose(out);
1181 float slope=0,intercept=0;
1184 if (verbose) printf(
"slope=%f intercept=%f\n",slope,intercept);
1186 float B=(float)
params[
"bfactor"]+slope*4.0f/2.0f;
1187 float B2=(float)
params[
"bfactor"];
1189 if (verbose) printf(
"User B = %1.2f Corrective B = %1.2f Total B=%1.3f\n",(
float)
params[
"bfactor"],slope*2.0,B);
1191 float cutval=exp(-B*pow(end*ds,2.0f)/4.0f)/exp(-B2*pow(end*ds,2.0f)/4.0f);
1192 for (
unsigned int i=0; i<radial_mask.size(); i++) {
1193 if (i<=end) radial_mask[i]=exp(-B*pow(i*ds,2.0f)/4.0f);
1194 else radial_mask[i]=cutval*exp(-B2*pow(i*ds,2.0f)/4.0f);
1204 size_t nxyz = image->get_size();
1208 for (
size_t i=0; i<nxyz; i++) {
1209 float v=image->get_value_at_index(i);
1210 float snr=(v>=.9999)?10000.0f:scale*v/(1.0f-v);
1211 if (snr<0) snr=0.0f;
1212 if (mode) image->set_value_at_index(i,snr/(1.0f+snr));
1213 else image->set_value_at_index(i,snr);
1220 int ys=image->get_ysize();
1223 mask1->process_inplace(
"mask.gaussian",
Dict(
"outer_radius", ys/2.0));
1224 EMData *mask2=mask1->copy();
1227 mask2->process_inplace(
"mask.decayedge2d",
Dict(
"width",4));
1263 if (!image->is_complex()) fft = image->do_fft();
1269 int nx=fft->get_xsize()/2;
1270 int ny=fft->get_ysize();
1273 for (
int x=1;
x<nx;
x++) fft->set_complex_at(
x,0,(fft->get_complex_at(
x,1)+fft->get_complex_at(
x,-1))/neighbornorm);
1276 for (
int x=1;
x<nx;
x++) fft->set_complex_at(
x,0,0.0f);
1281 for (
int y=1;
y<ny;
y++) fft->set_complex_at(0,
y,(fft->get_complex_at(-1,
y)+fft->get_complex_at(1,
y))/neighbornorm);
1284 for (
int y=1;
y<ny;
y++) fft->set_complex_at(0,
y,0.0f);
1290 EMData *ift=fft->do_ift();
1291 memcpy(image->get_data(),ift->get_data(),(nx*2-2)*ny*
sizeof(
float));
1303 image->set_attr(
"apix_x", (
float)
params[
"apix"]);
1304 image->set_attr(
"apix_y", (
float)
params[
"apix"]);
1305 image->set_attr(
"apix_z", (
float)
params[
"apix"]);
1310 const Dict dict = image->get_attr_dict();
1312 float val = (float)
params[
"cutoff_freq"] * (
float)dict[
"apix_x"];
1313 params[
"cutoff_abs"] = val;
1316 float val = ((float)
params[
"cutoff_pixels"] / (
float)dict[
"nx"]);
1317 params[
"cutoff_abs"] = val;
1320 float omega =
params[
"cutoff_abs"];
1324 omega = (omega<0?-1.0:1.0)*0.5f/omega/omega;
1334 if (!image->is_complex()) {
1335 fft = image->do_fft();
1342 int nx=fft->get_xsize();
1343 int ny=fft->get_ysize();
1344 int nz=fft->get_ysize();
1346 zcenter=zcenter*(float)dict[
"apix_x"]*nz;
1349 for (
int x=0;
x<nx/2;
x++) {
1350 for (
int z=(
x==0?0:-nz/2); z<nz/2; z++) {
1351 for (
int y=(
x==0&&z==0?0:-ny/2);
y<ny/2;
y++) {
1352 std::complex <float> v=fft->get_complex_at(
x,
y,z);
1354 fft->set_complex_at(
x,
y,z,v*exp(-omega*(r-zcenter)*(r-zcenter))*(r>hppix?1.0f:
Util::hypot3(
x,
y,z)/hppix));
1360 for (
int z=-nz/2; z<nz/2; z++) {
1361 for (
int y=-ny/2;
y<ny/2;
y++) {
1362 for (
int x=0;
x<nx/2;
x++) {
1363 std::complex <float> v=fft->get_complex_at(
x,
y,z);
1364 fft->set_complex_at(
x,
y,z,v*exp(-omega*(abs(z)-zcenter)*(abs(z)-zcenter))*(fabs(z)>hppix?1.0f:
Util::hypot3(
x,
y,z)/hppix));
1371 EMData *ift=fft->do_ift();
1372 memcpy(image->get_data(),ift->get_data(),(nx-2)*ny*nz*
sizeof(
float));
1393 if (!image->is_complex()) {
1394 fft = image->do_fft();
1395 fftd = fft->get_data();
1400 fftd=image->get_data();
1403 if (
sum) sumd=
sum->get_data();
1405 size_t n = (size_t)fft->get_xsize()*fft->get_ysize()*fft->get_zsize();
1406 for (
size_t i=0; i<n; i+=2) {
1408 if (
dosqrt) c=pow(fftd[i]*fftd[i]+fftd[i+1]*fftd[i+1],0.25f);
1409 else c =
static_cast<float>(hypot(fftd[i],fftd[i+1]));
1410 if (c==0) c=1.0e-30f;
1413 if (sumd) { sumd[i]+=c; sumd[i+1]+=0; }
1430 EMData *ift=fft->do_ift();
1431 memcpy(image->get_data(),ift->get_data(),n*
sizeof(
float));
1443 printf(
"Process inplace not implemented. Please use process.\n");
1457 float apix=image->get_attr(
"apix_x");
1458 int nx=image->get_xsize();
1459 int ny=image->get_ysize();
1460 int nz=image->get_zsize();
1462 EMData * result = image->process(
"threshold.belowtozero",
Dict(
"minval",0.0f));
1467 result->mult(*mask);
1468 result->process_inplace(
"normalize.local",
Dict(
"radius",nx*apix/(3.0f*width),
"threshold",(
float)result->get_attr(
"sigma_nonzero")*1.2));
1474 result->process_inplace(
"filter.setstrucfac",
Dict(
"apix",apix,
"strucfac",&gsf));
1477 int gs=2*width/(float)image->get_attr(
"apix_x");
1480 gsub.process_inplace(
"mask.gaussian",
Dict(
"outer_radius",
int(width/(2.0*apix))));
1483 result->set_attr(
"render_bits",12);
1484 result->set_attr(
"render_min",(
float)result->get_attr(
"minimum"));
1485 result->set_attr(
"render_max",(
float)result->get_attr(
"maximum"));
1490 if (skipseg==2) cache=result->copy();
1515 vector<float> centers;
1517 if (maxnseg==0) maxnseg=2000000000;
1519 float thr=(float)result->get_attr(
"maximum")*minratio;
1520 while (amps.size()<maxnseg) {
1521 if ((
float)result->get_attr(
"maximum")<=thr)
break;
1523 vector<Pixel> pixels=result->calc_highest_locations(thr);
1524 if (pixels.size()==0)
break;
1525 if (verbose>1) printf(
"%d %f %f %f %d\n",pixels.size(),pixels[0].get_value(),pixels[1].get_value(),pixels[2].get_value(),amps.size());
1527 for (
int i=0; i<pixels.size(); i++) {
1528 IntPoint p = pixels[i].get_point();
1531 float amp=result->get_value_at(p[0],p[1],p[2]);
1532 if (amp!=pixels[i].get_value())
continue;
1535 if (amp<thr)
continue;
1537 amps.push_back(amp);
1538 centers.push_back(p[0]);
1539 centers.push_back(p[1]);
1540 centers.push_back(p[2]);
1542 result->insert_scaled_sum(&gsub,fp,1.0,-amp);
1546 if (verbose) printf(
"Found %d centers\n",amps.size());
1549 result->set_attr(
"render_bits",12);
1550 result->set_attr(
"render_min",(
float)result->get_attr(
"minimum"));
1551 result->set_attr(
"render_max",(
float)result->get_attr(
"maximum"));
1556 for (
int z=0; z<nz; z++) {
1557 for (
int y=0;
y<ny;
y++) {
1558 for (
int x=0;
x<nz;
x++) {
1564 float bdist=(float)(nx+ny+nz);
1565 for (
unsigned int c=0; c<centers.size()/3; c++) {
1566 float d=
Util::hypot3(
x-centers[c*3],
y-centers[c*3+1],z-centers[c*3+2]);
1567 if (d<bdist) { bdist=d; bcls=c; }
1569 result->set_value_at(
x,
y,z,(
float)bcls);
1573 if (verbose) printf(
"segmented\n");
1582 result->set_attr(
"segment_centers",centers);
1583 result->set_attr(
"segment_amps",amps);
1590 printf(
"Process inplace not implemented. Please use process.\n");
1597 EMData * result = image->copy();
1604 vector<Pixel> pixels=image->calc_highest_locations(thr);
1606 vector<float> centers(3);
1607 int nx=image->get_xsize();
1608 int ny=image->get_ysize();
1609 int nz=image->get_zsize();
1613 centers[0]=(float)pixels[0].
x;
1614 centers[1]=(float)pixels[0].
y;
1615 centers[2]=(float)pixels[0].z;
1616 pixels.erase(pixels.begin());
1620 while (pixels.size()>0) {
1624 for (
unsigned int i=0; i<pixels.size(); i++) {
1628 for (
unsigned int j=0; j<centers.size(); j+=3) {
1629 float d=
Util::hypot3(centers[j]-p.
x,centers[j+1]-p.
y,centers[j+2]-p.
z);
1631 pixels.erase(pixels.begin()+i);
1639 for (
unsigned int i=0; i<pixels.size() && found==0; i++) {
1643 for (
unsigned int j=centers.size()-3; j>0; j-=3) {
1644 float d=
Util::hypot3(centers[j]-p.
x,centers[j+1]-p.
y,centers[j+2]-p.
z);
1646 centers.push_back((
float)p.
x);
1647 centers.push_back((
float)p.
y);
1648 centers.push_back((
float)p.
z);
1649 pixels.erase(pixels.begin()+i);
1657 if (!found && pixels.size()) {
1658 if (verbose) printf(
"New chain\n");
1659 centers.push_back((
float)pixels[0].
x);
1660 centers.push_back((
float)pixels[0].
y);
1661 centers.push_back((
float)pixels[0].z);
1662 pixels.erase(pixels.begin());
1665 if (verbose) printf(
"%d points found\n",(
int)(centers.size()/3));
1669 for (
int z=0; z<nz; z++) {
1670 for (
int y=0;
y<ny;
y++) {
1671 for (
int x=0;
x<nz;
x++) {
1672 if (image->get_value_at(
x,
y,z)<thr) {
1673 result->set_value_at(
x,
y,z,-1.0);
1677 float bdist=(float)(nx+ny+nz);
1678 for (
unsigned int c=0; c<centers.size()/3; c++) {
1679 float d=
Util::hypot3(
x-centers[c*3],
y-centers[c*3+1],z-centers[c*3+2]);
1680 if (d<bdist) { bdist=d; bcls=c; }
1682 result->set_value_at(
x,
y,z,(
float)bcls);
1687 result->set_attr(
"segment_centers",centers);
1695 if (s.length()<2)
return image->copy();
1696 int n=atoi(s.c_str()+1);
1697 if ((s[0]==
'c' || s[0]==
'C') && n==1)
return image->copy();
1701 if (image->get_zsize()==1) {
1702 if (s[0]!=
'c' && s[0]!=
'C')
throw ImageDimensionException(
"xform.applysym: Cn symmetry required for 2-D symmetrization");
1705 for (
int i=0; i<n; i++) {
1707 EMData* transformed = image->process(
"xform",
Dict(
"transform",&t));
1717 vector<Transform> transforms = sym->
get_syms();
1719 for(vector<Transform>::const_iterator trans_it = transforms.begin(); trans_it != transforms.end(); trans_it++) {
1721 EMData* transformed = image->process(
"xform",
Dict(
"transform",&t));
1733 memcpy(image->get_data(),tmp->get_data(),(
size_t)image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
1741 EMData * result = image->copy();
1754 int nx=image->get_xsize();
1755 int ny=image->get_ysize();
1756 int nz=image->get_zsize();
1760 thr=float(image->get_attr(
"mean_nonzero"))+ 1.0 *float(image->get_attr(
"sigma_nonzero"));
1761 printf(
"Estimated map threshold: %4f\n", thr);
1764 vector<float> centers(nseg*3);
1765 vector<float> count(nseg);
1768 float ax=image->get_attr(
"apix_x");
1770 if (verbose) printf(
"Seeding .....\n");
1771 int sx=int(nx/sep)+1,sy=int(ny/sep)+1,sz=int(nz/sep)+1;
1774 for (
int i=0; i<nx; i++){
1775 for (
int j=0; j<ny; j++){
1776 for (
int k=0; k<nz; k++){
1777 int ni=(i/sep),nj=(j/sep),nk=(k/sep);
1778 float v=image->get_value_at(i,j,k);
1780 m.set_value_at(ni,nj,nk,(m.get_value_at(ni,nj,nk)+v));
1781 mcount.set_value_at(ni,nj,nk,(mcount.get_value_at(ni,nj,nk)+1));
1786 m.div((nx/sx)*(ny/sy)*(nz/sz));
1788 float l=image->get_attr(
"minimum"),r=image->get_attr(
"maximum"),th=0;
1789 while (abs(nsum-nseg)>0){
1792 for (
int i=0; i<sx; i++){
1793 for (
int j=0; j<sy; j++){
1794 for (
int k=0; k<sz; k++){
1795 if (m.get_value_at(i,j,k)>th) nsum+=1;
1800 if (nsum>nseg) l=th;
1801 if (nsum<nseg) r=th;
1802 if ((r-l)<.0001)
break;
1805 if (verbose) printf(
"%3d pseudoatoms seeded at threshold value %3f\n", nsum, th);
1807 for (
int i=0; i<sx; i++){
1808 for (
int j=0; j<sy; j++){
1809 for (
int k=0; k<sz; k++){
1810 if (m.get_value_at(i,j,k)>th){
1812 centers[q]= float(i+.5)*sep;
1813 centers[q+1]=float(j+.5)*sep;
1814 centers[q+2]=float(k+.5)*sep;
1825 for (
int i=0; i<nseg*3; i+=3) {
1832 for (
int iter=0; iter<maxiter; iter++) {
1835 for (
int z=0; z<nz; z++) {
1836 for (
int y=0;
y<ny;
y++) {
1837 for (
int x=0;
x<nx;
x++) {
1838 if (image->get_value_at(
x,
y,z)<thr) {
1839 result->set_value_at(
x,
y,z,-1.0);
1843 float bdist=(float)(nx+ny+nz);
1844 for (
int c=0; c<nseg; c++) {
1845 float d=
Util::hypot3(
x-centers[c*3],
y-centers[c*3+1],z-centers[c*3+2]);
1846 if (d<bdist) { bdist=d; bcls=c; }
1848 if ((
int)result->get_value_at(
x,
y,z)!=bcls) pixmov++;
1849 if (bdist>maxsegsize) result->set_value_at(
x,
y,z,-1);
1850 else result->set_value_at(
x,
y,z,(
float)bcls);
1856 for (
int i=0; i<nseg*3; i++) centers[i]=0;
1857 for (
int i=0; i<nseg; i++) count[i]=0;
1859 for (
int z=0; z<nz; z++) {
1860 for (
int y=0;
y<ny;
y++) {
1861 for (
int x=0;
x<nx;
x++) {
1862 int cls = (int)result->get_value_at(
x,
y,z);
1863 if (cls==-1)
continue;
1865 if (ampweight) w=image->get_value_at(
x,
y,z);
1867 centers[cls*3]+=
x*w;
1868 centers[cls*3+1]+=
y*w;
1869 centers[cls*3+2]+=z*w;
1876 for (
int c=0; c<nseg; c++) {
1884 }
while (image->get_value_at((
int)centers[c*3],(
int)centers[c*3+1],(
int)centers[c*3+2])<thr);
1888 centers[c*3]/=count[c];
1889 centers[c*3+1]/=count[c];
1890 centers[c*3+2]/=count[c];
1896 for (
int c1=0; c1<nseg-1; c1++) {
1897 for (
int c2=c1+1; c2<nseg; c2++) {
1898 if (
Util::hypot3(centers[c1*3]-centers[c2*3],centers[c1*3+1]-centers[c2*3+1],centers[c1*3+2]-centers[c2*3+2])<=minsegsep) {
1904 }
while (image->get_value_at((
int)centers[c1*3],(
int)centers[c1*3+1],(
int)centers[c1*3+2])<thr);
1911 if (verbose) printf(
"Iteration %3d: %6ld voxels moved, %3d classes reseeded\n",iter,pixmov,nreseed);
1912 if (nreseed==0 && pixmov<(
size_t)maxvoxmove)
break;
1915 result->set_attr(
"segment_centers",centers);
1922 printf(
"Process inplace not implemented. Please use process.\n");
1931 int nx=image->get_xsize();
1932 int ny=image->get_ysize();
1933 int nz=image->get_zsize();
1941 for (
int z=0; z<nz; z++) {
1942 for (
int y=0;
y<ny;
y++) {
1943 for (
int x=0;
x<nx;
x++) {
1944 float xf=1.0-fabs(
x-x0)*2.0/xwidth;
1945 float yf=1.0-fabs(
y-y0)*2.0/ywidth;
1946 float zf=1.0-fabs(z-z0)*2.0/zwidth;
1948 if (xf>0&&yf>0&&zf>0) val=xf*yf*zf;
1949 image->mult_value_at_fast(
x,
y,z,val);
1984 memcpy(image->get_data(),tmp->get_data(),image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
1994 if (in->is_complex()) in2=in;
1995 else in=in->do_fft();
1997 EMData *filt = in->copy_head();
2000 if (!ictf)
ctf=(
Ctf *)in->get_attr(
"ctf");
2004 EMData *ret=filt->do_ift();
2007 if (!in->is_complex())
delete in2;
2045 memcpy(image->get_data(),tmp->get_data(),image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
2053 Assert(radial_mask.size() > 0);
2054 for (
size_t i = 0; i < radial_mask.size(); i++) {
2055 radial_mask[i] = (float)i;
2066 cutoff=(float)
params[
"cutoff_abs"];
2069 printf(
"A cutoff_* parameter is required by filter.lowpass.randomphase\n");
2074 if (image->get_zsize()==1) {
2076 if (!image->is_complex()) { image->do_fft_inplace(); flag=1; }
2078 int nx=image->get_xsize();
2079 int ny=image->get_ysize();
2082 float *data=image->get_data();
2083 for (
int y=-ny/2;
y<ny/2;
y++) {
2084 for (
int x=0;
x<nx/2+1;
x++) {
2085 if (hypot(
x/
float(nx),
y/
float(ny))>=cutoff) {
2086 size_t idx=image->get_complex_index_fast(
x,
y,z);
2095 image->do_ift_inplace();
2101 if (!image->is_complex()) { image->do_fft_inplace(); flag=1; }
2103 int nx=image->get_xsize();
2104 int ny=image->get_ysize();
2105 int nz=image->get_zsize();
2107 float *data=image->get_data();
2108 for (
int z=-nz/2; z<nz/2; z++) {
2109 for (
int y=-ny/2;
y<ny/2;
y++) {
2110 for (
int x=0;
x<nx/2;
x++) {
2112 size_t idx=image->get_complex_index_fast(
x,
y,z);
2121 image->do_ift_inplace();
2130 image->set_attr(
"apix_x", (
float)
params[
"apix"]);
2131 image->set_attr(
"apix_y", (
float)
params[
"apix"]);
2132 image->set_attr(
"apix_z", (
float)
params[
"apix"]);
2135 const Dict dict = image->get_attr_dict();
2141 highpass = (float)
params[
"cutoff_freq"] * (
float)dict[
"apix_x"] * (float)dict[
"ny"] / 2.0f;
2153 for (c=2; c<radial_mask.size(); c++)
if (radial_mask[c-1]<=radial_mask[c])
break;
2158 for (
unsigned int i=1; i<radial_mask.size(); i++) radial_mask[i]=(i<=c?0.0f:1.0f);
2167 Assert(radial_mask.size() > 0);
2168 float x = 0.0f , step = 0.5f/radial_mask.size();
2169 size_t size=radial_mask.size();
2170 for (
size_t i = 0; i < size; i++) {
2179 Assert(radial_mask.size() > 0);
2180 float x = 0.0f , nqstep = 0.5f/radial_mask.size();
2181 size_t size=radial_mask.size();
2183 for (
size_t i = 0; i < size; i++) {
2184 radial_mask[i] = ((
x*
x - var)/var*var)*exp(-
x*
x/2*var);
2192 Assert(radial_mask.size() > 0);
2193 float x = 0.0f , nqstep = 0.5f/radial_mask.size();
2194 size_t size=radial_mask.size();
2195 float norm = 1.0f/
sqrt(2*M_PI);
2196 for (
size_t i = 0; i < size; i++) {
2211 if (gauss_width<=0) {
2212 size_t size = (size_t)image->get_xsize() *
2213 (size_t)image->get_ysize() *
2214 (size_t)image->get_zsize();
2215 float *data = image->get_data();
2217 for (
size_t i = 0; i < size; ++i) {
2223 int nx = image->get_xsize();
2224 int ny = image->get_ysize();
2225 int nz = image->get_zsize();
2226 float wid=gauss_width/(ny*ny);
2228 for (
int z=0; z<nz; z++) {
2229 for (
int y=0;
y<ny;
y++) {
2230 for (
int x=0;
x<nx;
x++) {
2232 if (image->get_value_at(
x,
y,z)>=
minval*cor && image->get_value_at(
x,
y,z)<=
maxval*cor) image->set_value_at(
x,
y,z,0.0f);
2250 maxval = image->get_attr(
"maximum");
2251 mean = image->get_attr(
"mean");
2252 sigma = image->get_attr(
"sigma");
2256 size_t size = (size_t)image->get_xsize() *
2257 (size_t)image->get_ysize() *
2258 (size_t)image->get_zsize();
2259 float *data = image->get_data();
2261 for (
size_t i = 0; i < size; ++i) {
2275 maxval = image->get_attr(
"maximum");
2276 mean = image->get_attr(
"mean");
2277 sigma = image->get_attr(
"sigma");
2278 nx = image->get_xsize();
2279 ny = image->get_ysize();
2280 nz = image->get_zsize();
2290 float *data = image->get_data();
2293 for (
int z = 0; z <
nz; z++) {
2294 for (
int y = 0;
y <
ny;
y++) {
2295 for (
int x = 0;
x <
nx;
x++) {
2305 int nx=image->get_xsize();
2306 int ny=image->get_ysize();
2307 int nz=image->get_zsize();
2314 if (r>
r2 && r>
r1)
continue;
2316 else image->set_value_at(i,j,0,
v1);
2326 if (r>
r2 && r>
r1)
continue;
2328 else image->set_value_at(i,j,k,
v1);
2337 if (image->is_complex())
throw ImageFormatException(
"MaskAzProcessor: target image must be real");
2339 int nx=image->get_xsize();
2340 int ny=image->get_ysize();
2341 int nz=image->get_zsize();
2356 for (
int x=0;
x<nx;
x++) {
2357 for (
int y=0;
y<ny;
y++) {
2358 float az=atan2(
y-cy,
x-cx);
2359 float az2=az-M_PI*2.0f;
2360 float az3=az+M_PI*2.0f;
2361 float r=hypot(
y-cy,
x-cx);
2363 if (r>inner_radius&&r<=outer_radius) {
2365 if (as<phirange) val=1.0f;
2366 else if (!phitriangle || as>phirange+phitrirange) val=0.0f;
2367 else val=1.0-(as-phirange)/
float(phitrirange);
2369 if (r==0 && inner_radius<=0) val=1.0;
2371 for (
int z=0; z<nz; z++) {
2372 if (z<zmin-ztri || z>zmax+ztri) image->mult_value_at_fast(
x,
y,z,0);
2373 else if (z>=zmin+ztri && z<=zmax-ztri) image->mult_value_at_fast(
x,
y,z,val);
2374 else if (z>=zmin-ztri && z<=zmin+ztri) image->mult_value_at_fast(
x,
y,z,val*((z-zmin)/(2.0f*ztri)+0.5));
2375 else image->mult_value_at_fast(
x,
y,z,val*((zmax-z)/(2.0f*ztri)+0.5));
2406 float *data = image->get_data();
2413 for (
int z = 0; z <
nz; ++z) {
2414 for (
int y = 0;
y <
ny; ++
y) {
2415 for (
int x = 0;
x <
nx; ++
x) {
2439 size_t size = (size_t)image->get_xsize() *
2440 (size_t)image->get_ysize() *
2441 (size_t)image->get_zsize();
2442 float *data = image->get_data();
2446 for (
size_t i = 0; i < size; ++i) {
2447 if (data[i]<minval) data[i]=newval;
2459 if (!image->is_complex()) {
2460 LOGWARN(
"cannot apply complex processor on a real image. Nothing is done.");
2464 size_t size = (size_t)image->get_xsize() *
2465 (size_t)image->get_ysize() *
2466 (size_t)image->get_zsize();
2467 float *data = image->get_data();
2471 for (
size_t i = 0; i < size; i += 2) {
2489 float *data = image->get_data();
2491 nx = image->get_xsize();
2492 ny = image->get_ysize();
2493 nz = image->get_zsize();
2505 size_t cpysize =
areasize *
sizeof(float);
2506 size_t start = (
nx *
ny +
nx + 1) * n;
2523 size_t nsec = (size_t)
nx * (
size_t)
ny;
2528 size_t total_size = (size_t)
nx * (
size_t)
ny * (size_t)
nz;
2529 float *data2 =
new float[total_size];
2530 memcpy(data2, data, total_size *
sizeof(
float));
2533 for (
int z = zstart; z < zend; z++) {
2534 for (
int y = n;
y < yend;
y++) {
2535 for (
int x = n;
x < xend;
x++) {
2537 k = (size_t)z * nsec +
y *
nx +
x;
2539 for (
int bz = zbox_start; bz < zbox_end; bz++) {
2540 for (
int by = 0; by <
areasize; by++) {
2541 memcpy(&matrix[(
size_t)bz * box_nsec + by *
areasize],
2542 &data2[k - start + bz * nsec + by *
nx], cpysize);
2568 d = image->process(
"math.edge.xgradient");
2569 d->process_inplace(
"math.edge.xgradient");
2570 image->process_inplace(
"math.edge.ygradient");
2571 image->process_inplace(
"math.edge.xgradient");
2573 image->process_inplace(
"normalize");
2589 kernel[4] = -1.0f / 6.0f;
2590 kernel[10] = -1.0f / 6.0f;
2591 kernel[12] = -1.0f / 6.0f;
2592 kernel[14] = -1.0f / 6.0f;
2593 kernel[16] = -1.0f / 6.0f;
2594 kernel[22] = -1.0f / 6.0f;
2606 float sigma = image->get_attr(
"sigma");
2607 float mean = image->get_attr(
"mean");
2608 float bitmax=pow(2.,bits);
2610 int nx = image->get_xsize();
2611 int ny = image->get_ysize();
2612 int nz = image->get_zsize();
2613 size_t total_size = (size_t)nx * (
size_t)ny * (size_t)nz;
2616 float min=image->get_attr(
"minimum");
2617 float max=image->get_attr(
"maximum");
2622 if (mean-nsigma*sigma>min) min=mean-nsigma*sigma;
2623 if (mean+nsigma*sigma<max) max=mean+nsigma*sigma;
2626 for (
size_t i=0; i<total_size; i++) {
2627 float newval=floor((image->get_value_at_index(i)-min)*bitmax/(max-min)
2630 if (newval<0) newval=0;
2631 if (newval>=bitmax) newval=bitmax-1.0f;
2632 image->set_value_at_index(i,newval);
2638 unsigned int bitmask= 0xffffffff << (23-floatbits);
2639 for (
size_t i=0; i<total_size; i++) {
2640 float newval=image->get_value_at_index(i);
2641 unsigned int *newvali = (
unsigned int*)&newval;
2643 image->set_value_at_index(i,newval);
2651 memcpy(image->get_data(),cpy->get_data(),image->get_size()*
sizeof(
float));
2656inline int MIRE(
int x,
int nx) {
return x<0?-
x:(
x>=nx?nx-(
x-nx+1):
x); }
2666 int nx = image->get_xsize();
2667 int ny = image->get_ysize();
2668 int nz = image->get_zsize();
2677 int matrix_size = (2*dx+1)*(2*dy+1)*(2*dz+1);
2679 vector<float> array(matrix_size);
2682 EMData *ret = image->copy_head();
2687 for (
int k=0; k<nz; k++) {
2688 for (
int j=0; j<ny; j++) {
2689 for (
int i=0; i<nx; i++) {
2691 for (
int kk=k-dz,s=0; kk<=k+dz; kk++) {
2692 for (
int jj=j-dy; jj<=j+dy; jj++) {
2693 for (
int ii=i-dx; ii<=i+dx; ii++,s++) {
2694 array[s]=image->get_value_at(
MIRE(ii,nx),
MIRE(jj,ny),
MIRE(kk,nz));
2698 float newv=image->get_value_at(i,j,k);
2700 ret->set_value_at(i,j,k,newv);
2717 int nz = image->get_zsize();
2724 int nx = image->get_xsize();
2725 int ny = image->get_ysize();
2727 int v1 =
params[
"cal_half_width"];
2728 int v2 =
params[
"fill_half_width"];
2730 int v0 = v1 > v2 ? v1 : v2;
2736 float *data = image->get_data();
2738 for (
int y =
v0;
y <= ny -
v0 - 1;
y += v2) {
2739 for (
int x =
v0;
x <= nx -
v0 - 1;
x += v2) {
2742 for (
int y1 =
y - v1; y1 <=
y + v1; y1++) {
2743 for (
int x1 =
x - v1; x1 <=
x + v1; x1++) {
2744 sum += data[x1 + y1 * nx];
2747 float mean = sum / ((v1 * 2 + 1) * (v1 * 2 + 1));
2749 for (
int j =
y - v2; j <=
y + v2; j++) {
2750 for (
int i =
x - v2; i <=
x + v2; i++) {
2751 data[i + j * nx] = mean;
2767 int nz = image->get_zsize();
2774 int nx = image->get_xsize();
2775 int ny = image->get_ysize();
2777 float value1 =
params[
"value1"];
2778 float value2 =
params[
"value2"];
2780 int v1 = (int) value1;
2781 int v2 = (int) value2;
2783 LOGERR(
"invalid value2 '%f' in CutoffBlockProcessor", value2);
2791 float *data = image->get_data();
2793 for (
y = 0;
y <= ny - v1;
y += v1) {
2794 for (
x = 0;
x <= nx - v1;
x += v1) {
2797 EMData *fft = clip->do_fft();
2799 float *fft_data = fft->get_data();
2803 for (
int i = -v2; i < v2; i++) {
2804 for (
int j = 0; j < v2; j++) {
2805 if (j == 0 && i == 0) {
2809 if (hypot(j, i) < value2) {
2810 int t = j * 2 + (i + v1 / 2) * (v1 + 2);
2811 sum += (fft_data[t] * fft_data[t] + fft_data[t + 1] * fft_data[t + 1]);
2823 float mean = sum / nitems;
2825 for (
int i =
y; i <
y + v1; i++) {
2826 for (
int j =
x; j <
x + v1; j++) {
2827 data[i * nx + j] = mean;
2833 memset(&data[
y * nx], 0, (ny -
y) * nx *
sizeof(
float));
2835 for (
int i = 0; i < ny; i++) {
2836 memset(&data[i * nx +
x], 0, (nx -
x) *
sizeof(
float));
2844 if (image->is_complex())
throw ImageFormatException(
"Error, the median shrink processor does not work on complex images");
2847 if (shrink_factor <= 1) {
2849 "median shrink: shrink factor must > 1");
2852 int nx = image->get_xsize();
2853 int ny = image->get_ysize();
2854 int nz = image->get_zsize();
2861 int shrunken_nx = nx / shrink_factor;
2862 int shrunken_ny = ny / shrink_factor;
2863 int shrunken_nz = 1;
2864 if (nz > 1) shrunken_nz = nz / shrink_factor;
2867 image->set_size(shrunken_nx, shrunken_ny, shrunken_nz);
2880 if (image->is_complex())
throw ImageFormatException(
"Error, the median shrink processor does not work on complex images");
2883 if (shrink_factor <= 1) {
2885 "median shrink: shrink factor must > 1");
2887 int nx = image->get_xsize();
2888 int ny = image->get_ysize();
2889 int nz = image->get_zsize();
2897 int shrunken_nx = nx / shrink_factor;
2898 int shrunken_ny = ny / shrink_factor;
2899 int shrunken_nz = 1;
2900 if (nz > 1) shrunken_nz = nz / shrink_factor;
2903 EMData *ret = image->copy_head();
2904 ret->set_size(shrunken_nx, shrunken_ny, shrunken_nz);
2914 int nx_old = from->get_xsize();
2915 int ny_old = from->get_ysize();
2917 int threed_shrink_factor = shrink_factor * shrink_factor;
2918 int z_shrink_factor = 1;
2919 if (from->get_zsize() > 1) {
2920 threed_shrink_factor *= shrink_factor;
2921 z_shrink_factor = shrink_factor;
2924 float *mbuf =
new float[threed_shrink_factor];
2927 int nxy_old = nx_old * ny_old;
2929 int nx = to->get_xsize();
2930 int ny = to->get_ysize();
2931 int nz = to->get_zsize();
2932 int nxy_new = nx * ny;
2934 float *
rdata = to->get_data();
2935 const float *
const data_copy = from->get_const_data();
2937 for (
int l = 0; l < nz; l++) {
2938 int l_min = l * shrink_factor;
2939 int l_max = l * shrink_factor + z_shrink_factor;
2940 size_t cur_l = (size_t)l * nxy_new;
2942 for (
int j = 0; j < ny; j++) {
2943 int j_min = j * shrink_factor;
2944 int j_max = (j + 1) * shrink_factor;
2945 size_t cur_j = j * nx + cur_l;
2947 for (
int i = 0; i < nx; i++) {
2948 int i_min = i * shrink_factor;
2949 int i_max = (i + 1) * shrink_factor;
2952 for (
int l2 = l_min; l2 < l_max; l2++) {
2953 size_t cur_l2 = l2 * nxy_old;
2955 for (
int j2 = j_min; j2 < j_max; j2++) {
2956 size_t cur_j2 = j2 * nx_old + cur_l2;
2958 for (
int i2 = i_min; i2 < i_max; i2++) {
2959 mbuf[k] = data_copy[i2 + cur_j2];
2965 for (k = 0; k < size_t(threed_shrink_factor / 2 + 1); k++) {
2966 for (
int i2 = k + 1; i2 < threed_shrink_factor; i2++) {
2967 if (mbuf[i2] < mbuf[k]) {
2975 rdata[i + cur_j] = mbuf[threed_shrink_factor / 2];
2986 to->scale_pixel((
float)shrink_factor);
2991 if (image->is_complex())
throw ImageFormatException(
"FFTResampleProcessor does not support complex images.");
2994 if (sample_rate <= 0.0F ) {
2998 int nx=image->get_xsize();
2999 int ny=image->get_ysize();
3000 int nz=image->get_zsize();
3002 int nnx=(int)floor(nx/sample_rate+0.5f);
3003 int nny=(ny==1?1:(int)floor(ny/sample_rate+0.5f));
3004 int nnz=(nz==1?1:(int)floor(nz/sample_rate+0.5f));
3006 if (nnx==nx && nny==ny && nnz==nz)
return image->copy();
3010 if (nnx<nx||nny<ny||nnz<nz) {
3012 result=((
EMData *)image)->FourTruncate(nnx, nny, nnz, 1, 0);
3016 result=((
EMData *)image)->FourInterpol(nnx, nny, nnz, 1, 0);
3018 result->scale_pixel((
float)nx/(float)nnx);
3036 if (sample_rate <= 0.0F ) {
3041 int nx=image->get_xsize();
3042 int ny=image->get_ysize();
3043 int nz=image->get_zsize();
3045 int nnx=(int)floor(nx/sample_rate+0.5f);
3046 int nny=(ny==1?1:(int)floor(ny/sample_rate+0.5f));
3047 int nnz=(nz==1?1:(int)floor(nz/sample_rate+0.5f));
3049 if (nnx==nx && nny==ny && nnz==nz)
return;
3053 if (nnx<nx||nny<ny||nnz<nz) {
3055 result=((
EMData *)image)->FourTruncate(nnx, nny, nnz, 1, 0);
3059 result=((
EMData *)image)->FourInterpol(nnx, nny, nnz, 1, 0);
3062 image->set_size(nnx,nny,nnz);
3063 memcpy(image->get_data(),result->get_data(),nnx*nny*nnz*
sizeof(
float));
3064 image->scale_pixel((
float)nx/(
float)nnx);
3075 int nx = from->get_xsize();
3076 int ny = from->get_ysize();
3077 int nz = from->get_zsize();
3079 int new_nx =
static_cast<int>(
static_cast<float> (nx) / sample_rate);
3080 int new_ny =
static_cast<int>(
static_cast<float> (ny) / sample_rate);
3081 int new_nz =
static_cast<int>(
static_cast<float> (nz) / sample_rate);
3083 if (new_nx == 0)
throw UnexpectedBehaviorException(
"The resample rate causes the pixel dimensions in the x direction to go to zero");
3084 if (new_ny == 0) new_ny = 1;
3085 if (new_nz == 0) new_nz = 1;
3087 int ndim = from->get_ndim();
3095 int fft_x_correction = 1;
3096 if (new_nx % 2 == 0) fft_x_correction = 2;
3098 int fft_y_correction = 0;
3099 if (ny != 1 && new_ny % 2 == 0 && ny % 2 == 1) fft_y_correction = 1;
3100 else if (ny != 1 && new_ny % 2 == 1 && ny % 2 == 0) fft_y_correction = -1;
3102 int fft_z_correction = 0;
3103 if (nz != 1 && new_nz % 2 == 0 && nz % 2 == 1) fft_z_correction = 1;
3104 else if (nz != 1 && new_nz % 2 == 1 && nz % 2 == 0) fft_z_correction = -1;
3106 if ( ! to->is_complex()) to->do_fft_inplace();
3108 if (ndim != 1) to->process_inplace(
"xform.fourierorigin.tocenter");
3110 Region clip(0,(ny-new_ny)/2-fft_y_correction,(nz-new_nz)/2-fft_z_correction,new_nx+fft_x_correction,new_ny,new_nz);
3113 if (fft_x_correction == 1) to->set_fftodd(
true);
3114 else to->set_fftodd(
false);
3116 if (ndim != 1) to->process_inplace(
"xform.fourierorigin.tocorner");
3118 to->do_ift_inplace();
3126 if (image->is_complex())
throw ImageFormatException(
"Error, the mean shrink processor does not work on complex images");
3128 if (image->get_ndim() == 1) {
throw ImageDimensionException(
"Error, mean shrink works only for 2D & 3D images"); }
3131 int shrink_factor = int(shrink_factor0);
3132 if (shrink_factor0 <= 1.0F || ((shrink_factor0 != shrink_factor) && (shrink_factor0 != 1.5F) ) ) {
3134 "mean shrink: shrink factor must be >1 integer or 1.5");
3137 int nx = image->get_xsize();
3138 int ny = image->get_ysize();
3139 int nz = image->get_zsize();
3143 if (shrink_factor0==1.5 ) {
3144 if (nz > 1 )
throw InvalidValueException(shrink_factor0,
"mean shrink: only support 2D images for shrink factor = 1.5");
3146 int shrunken_nx = (int(nx / 1.5)+1)/2*2;
3147 int shrunken_ny = (int(ny / 1.5)+1)/2*2;
3148 EMData* result =
new EMData(shrunken_nx,shrunken_ny,1);
3156 int shrunken_nx = nx / shrink_factor;
3157 int shrunken_ny = ny / shrink_factor;
3158 int shrunken_nz = 1;
3161 shrunken_nz = nz / shrink_factor;
3165 EMData* result = image->copy_head();
3166 result->set_size(shrunken_nx,shrunken_ny,shrunken_nz);
3176 if (image->is_complex())
throw ImageFormatException(
"Error, the mean shrink processor does not work on complex images");
3178 if (image->get_ndim() == 1) {
throw ImageDimensionException(
"Error, mean shrink works only for 2D & 3D images"); }
3181 int shrink_factor = int(shrink_factor0);
3182 if (shrink_factor0 <= 1.0F || ((shrink_factor0 != shrink_factor) && (shrink_factor0 != 1.5F) ) ) {
3184 "mean shrink: shrink factor must be >1 integer or 1.5");
3193 int nx = image->get_xsize();
3194 int ny = image->get_ysize();
3195 int nz = image->get_zsize();
3197 if (shrink_factor0==1.5 ) {
3198 if (nz > 1 )
throw InvalidValueException(shrink_factor0,
"mean shrink: only support 2D images for shrink factor = 1.5");
3200 int shrunken_nx = (int(nx / 1.5)+1)/2*2;
3201 int shrunken_ny = (int(ny / 1.5)+1)/2*2;
3203 EMData* orig = image->copy();
3204 image->set_size(shrunken_nx, shrunken_ny, 1);
3220 int shrunken_nx = nx / shrink_factor;
3221 int shrunken_ny = ny / shrink_factor;
3222 int shrunken_nz = 1;
3223 if (nz > 1) shrunken_nz = nz / shrink_factor;
3226 image->set_size(shrunken_nx, shrunken_ny, shrunken_nz);
3231 const float *
const data = from->get_const_data();
3232 float*
rdata = to->get_data();
3234 size_t nx = from->get_xsize();
3235 size_t ny = from->get_ysize();
3236 size_t nz = from->get_zsize();
3240 size_t shrunken_nx = nx / shrink_factor;
3241 size_t shrunken_ny = ny / shrink_factor;
3242 size_t shrunken_nz = 1;
3243 size_t shrunken_nxy = shrunken_nx * shrunken_ny;
3245 int normalize_shrink_factor = shrink_factor * shrink_factor;
3246 int z_shrink_factor = 1;
3249 shrunken_nz = nz / shrink_factor;
3250 normalize_shrink_factor *= shrink_factor;
3251 z_shrink_factor = shrink_factor;
3254 float invnormfactor = 1.0f/(float)normalize_shrink_factor;
3256 for (
size_t k = 0; k < shrunken_nz; k++) {
3257 size_t k_min = k * shrink_factor;
3258 size_t k_max = k * shrink_factor + z_shrink_factor;
3259 size_t cur_k = k * shrunken_nxy;
3261 for (
size_t j = 0; j < shrunken_ny; j++) {
3262 size_t j_min = j * shrink_factor;
3263 size_t j_max = j * shrink_factor + shrink_factor;
3264 size_t cur_j = j * shrunken_nx + cur_k;
3266 for (
size_t i = 0; i < shrunken_nx; i++) {
3267 size_t i_min = i * shrink_factor;
3268 size_t i_max = i * shrink_factor + shrink_factor;
3271 for (
size_t kk = k_min; kk < k_max; kk++) {
3272 size_t cur_kk = kk * nxy;
3274 for (
size_t jj = j_min; jj < j_max; jj++) {
3275 size_t cur_jj = jj * nx + cur_kk;
3276 for (
size_t ii = i_min; ii < i_max; ii++) {
3277 sum += data[ii + cur_jj];
3281 rdata[i + cur_j] = sum * invnormfactor;
3285 to->scale_pixel((
float)shrink_factor);
3291 int nx0 = from->get_xsize(), ny0 = from->get_ysize();
3293 int nx = to->get_xsize(), ny = to->get_ysize();
3295 float *data = to->get_data();
3296 const float *
const data0 = from->get_const_data();
3298 for (
int j = 0; j < ny; j++) {
3299 int jj = int(j * 1.5);
3300 float jw0 = 1.0F, jw1 = 0.5F;
3305 for (
int i = 0; i < nx; i++) {
3306 int ii = int(i * 1.5);
3307 float iw0 = 1.0F, iw1 = 0.5F;
3316 data[j * nx + i] = data0[ jj * nx0 + ii ] * jw0 * iw0 ;
3319 data[j * nx + i] += data0[ jj * nx0 + ii + 1] * jw0 * iw1;
3323 if ( jj +1 < ny0 ) {
3325 data[j * nx + i] += data0[ (jj+1) * nx0 + ii ] * jw1 * iw0;
3328 data[j * nx + i] += data0[ (jj+1) * nx0 + ii + 1] * jw1 * iw1;
3334 if ( w>0 ) data[j * nx + i] /= w;
3339 to->scale_pixel((
float)1.5);
3343template<
class LogicOp>
3360 int nz = image->get_zsize();
3361 int ny = image->get_ysize();
3362 int nx = image->get_xsize();
3364 if (nx == 1 && ny == 1 && nz == 1 )
return image->copy();
3369 int shrinkx = shrink;
3370 int shrinky = shrink;
3371 int shrinkz = shrink;
3373 int searchx = search;
3374 int searchy = search;
3375 int searchz = search;
3379 if ( shrinkx > nx ) shrinkx = nx;
3380 if ( shrinky > ny ) shrinky = ny;
3381 if ( shrinkz > nz ) shrinkz = nz;
3383 if ( nz == 1 && ny == 1 )
3385 return_image->set_size(nx/shrinkx);
3386 for(
int i = 0; i < nx/shrinkx; ++i)
3388 float tmp = op.get_start_val();
3389 for(
int s=0; s < searchx; ++s)
3391 int idx = shrinkx*i+s;
3393 if ( idx > nx )
break;
3396 float val = image->get_value_at(idx);
3397 if ( op( val,tmp) ) tmp = val;
3400 return_image->set_value_at(i,tmp);
3405 int ty = ny/shrinky;
3406 int tx = nx/shrinkx;
3407 return_image->set_size(tx,ty);
3408 for(
int y = 0;
y < ty; ++
y) {
3409 for(
int x = 0;
x < tx; ++
x) {
3410 float tmp = op.get_start_val();
3411 for(
int sy=0; sy < searchy; ++sy) {
3412 int yidx = shrinky*
y+sy;
3413 if ( yidx >= ny)
break;
3414 for(
int sx=0; sx < searchx; ++sx) {
3415 int xidx = shrinkx*
x+sx;
3416 if ( xidx >= nx)
break;
3418 float val = image->get_value_at(xidx,yidx);
3419 if ( op( val,tmp) ) tmp = val;
3422 return_image->set_value_at(
x,
y,tmp);
3428 int tz = nz/shrinkz;
3429 int ty = ny/shrinky;
3430 int tx = nx/shrinkx;
3432 return_image->set_size(tx,ty,tz);
3433 for(
int z = 0; z < tz; ++z) {
3434 for(
int y = 0;
y < ty; ++
y) {
3435 for(
int x = 0;
x < tx; ++
x) {
3436 float tmp = op.get_start_val();
3438 for(
int sz=0; sz < searchz; ++sz) {
3439 int zidx = shrinkz*z+sz;
3440 if ( zidx >= nz)
break;
3442 for(
int sy=0; sy < searchy; ++sy) {
3443 int yidx = shrinky*
y+sy;
3444 if ( yidx >= ny)
break;
3446 for(
int sx=0; sx < searchx; ++sx) {
3447 int xidx = shrinkx*
x+sx;
3448 if ( xidx >= nx)
break;
3449 float val = image->get_value_at(xidx,yidx,zidx);
3450 if ( op( val,tmp) ) tmp = val;
3454 return_image->set_value_at(
x,
y,z,tmp);
3459 return_image->update();
3461 return return_image;
3464template<
class LogicOp>
3480 int nz = image->get_zsize();
3481 int ny = image->get_ysize();
3482 int nx = image->get_xsize();
3486 int shrinkx = shrink;
3487 int shrinky = shrink;
3488 int shrinkz = shrink;
3490 int searchx = search;
3491 int searchy = search;
3492 int searchz = search;
3496 if ( shrinkx > nx ) shrinkx = nx;
3497 if ( shrinky > ny ) shrinky = ny;
3498 if ( shrinkz > nz ) shrinkz = nz;
3500 if (nx == 1 && ny == 1 && nz == 1 )
return;
3502 if ( nz == 1 && ny == 1 )
3504 for(
int i = 0; i < nx/shrink; ++i)
3506 float tmp = op.get_start_val();
3507 for(
int s=0; s < searchx; ++s)
3509 int idx = shrinkx*i+s;
3510 if ( idx > nx )
break;
3513 float val = image->get_value_at(idx);
3514 if ( op( val,tmp) ) tmp = val;
3517 image->set_value_at(i,tmp);
3520 image->set_size(nx/shrinkx);
3524 int ty = ny/shrinky;
3525 int tx = nx/shrinkx;
3526 for(
int y = 0;
y < ty; ++
y) {
3527 for(
int x = 0;
x < tx; ++
x) {
3528 float tmp = op.get_start_val();
3529 for(
int sy=0; sy < searchy; ++sy) {
3530 int yidx = shrinky*
y+sy;
3531 if ( yidx >= ny)
break;
3532 for(
int sx=0; sx < searchx; ++sx) {
3533 int xidx = shrinkx*
x+sx;
3534 if ( xidx >= nx)
break;
3536 float val = image->get_value_at(xidx,yidx);
3537 if ( op( val,tmp) ) tmp = val;
3540 (*image)(
x+tx*
y) = tmp;
3543 image->set_size(tx,ty);
3547 int tnxy = nx/shrinkx*ny/shrinky;
3548 int tz = nz/shrinkz;
3549 int ty = ny/shrinky;
3550 int tx = nx/shrinkx;
3552 for(
int z = 0; z < tz; ++z) {
3553 for(
int y = 0;
y < ty; ++
y) {
3554 for(
int x = 0;
x < tx; ++
x) {
3555 float tmp = op.get_start_val();
3556 for(
int sz=0; sz < searchz; ++sz) {
3557 int zidx = shrinkz*z+sz;
3558 if ( zidx >= nz)
break;
3559 for(
int sy=0; sy < searchy; ++sy) {
3560 int yidx = shrinky*
y+sy;
3561 if ( yidx >= ny)
break;
3562 for(
int sx=0; sx < shrinkx; ++sx) {
3563 int xidx = shrinkx*
x+sx;
3564 if ( xidx >= nx)
break;
3566 float val = image->get_value_at(xidx,yidx,zidx);
3567 if ( op( val,tmp) ) tmp = val;
3571 (*image)(
x+tx*
y+tnxy*z) = tmp;
3575 image->set_size(tx,ty,tz);
3589 int nz = image->get_zsize();
3591 LOGERR(
"%s Processor doesn't support 3D model",
get_name().c_str());
3595 int nx = image->get_xsize();
3596 int ny = image->get_ysize();
3597 float *dy =
new float[ny];
3601 float *data = image->get_data();
3603 for (
int i = 0; i < ny; i++) {
3609 float mean_y = sum_y / ny;
3613 for (
int j = 0; j < ny; j++) {
3614 for (
int i = 0; i < nx; i++) {
3615 data[i + j * nx] -= i * sum_x + j * mean_y + b;
3628 if (radius != 0 && mask != 0)
throw InvalidParameterException(
"Error - the mask and radius parameters are mutually exclusive.");
3630 if (mask == 0 && radius == 0)
throw InvalidParameterException(
"Error - you must specify either the mask or the radius parameter.");
3633 bool deletemask =
false;
3636 int n = image->get_ndim();
3638 mask->set_size(2*radius+1);
3640 mask->set_size(2*radius+1,2*radius+1);
3643 mask->set_size(2*radius+1,2*radius+1,2*radius+1);
3646 mask->process_inplace(
"testimage.circlesphere");
3650 int mnx = mask->get_xsize();
int mny = mask->get_ysize();
int mnz = mask->get_zsize();
3651 int nx = image->get_xsize();
int ny = image->get_ysize();
int nz = image->get_zsize();
3652 int nxc = nx+mnx;
int nyc = ny+mny;
int nzc = nz+mnz;
3653 if (nz == 1) nzc = 1;
3654 if (ny == 1) nyc = 1;
3656 if ( mnx > nx || mny > ny || mnz > nz)
3660 float normfac = 0.0;
3661 for (
int i=0; i<mask->get_xsize()*mask->get_ysize()*mask->get_zsize(); ++i){
3662 normfac += mask->get_value_at(i);
3667 if (normfac == 0)
throw InvalidParameterException(
"Error - the pixels in the mask sum to zero. This breaks the flattening procedure");
3668 normfac = 1.0f/normfac;
3674 if (ny == 1) r =
Region((mnx-nxc)/2,nxc);
3675 else if (nz == 1) r =
Region((mnx-nxc)/2, (mny-nyc)/2,nxc,nyc);
3676 else r =
Region((mnx-nxc)/2, (mny-nyc)/2,(mnz-nzc)/2,nxc,nyc,nzc);
3686 if (ny == 1) r2 =
Region((nx-nxc)/2,nxc);
3687 else if (nz == 1) r2 =
Region((nx-nxc)/2, (ny-nyc)/2,nxc,nyc);
3688 else r2 =
Region((nx-nxc)/2, (ny-nyc)/2,(nz-nzc)/2,nxc,nyc,nzc);
3695 m->process_inplace(
"xform.phaseorigin.tocenter");
3706 if (ny == 1) r =
Region((nxc-mnx)/2,mnx);
3707 else if (nz == 1) r =
Region((nxc-mnx)/2, (nyc-mny)/2,mnx,mny);
3708 else r =
Region((nxc-mnx)/2, (nyc-mny)/2,(nzc-mnz)/2,mnx,mny,mnz);
3713 if (ny == 1) r3 =
Region((nxc-nx)/2,nx);
3714 else if (nz == 1) r3 =
Region((nxc-nx)/2, (nyc-ny)/2,nx,ny);
3715 else r3 =
Region((nxc-nx)/2, (nyc-ny)/2,(nzc-nz)/2,nx,ny,nz);
3725 if (!image) {
LOGWARN(
"NULL IMAGE");
return; }
3729 if (image->get_ysize()==1) {
3733 else if (image->get_zsize()==1) {
3735 int nx2=image->get_xsize()/2;
3736 int ny2=image->get_ysize()/2;
3739 for (
int i=1; i<nx2; i++) {
3740 if (rdist[i]>rdist[i-1]) rdist[i]=rdist[i-1];
3743 image->process_inplace(
"xform.fourierorigin.tocenter");
3744 EMData* binary=image->copy();
3747 for (
int x=0;
x<image->get_xsize();
x+=2) {
3748 for (
int y=1;
y<image->get_ysize()-1;
y++) {
3749 int r=(int)hypot((
float)(
x/2),(
float)(
y-ny2));
3750 float cen=(*binary)(
x,
y);
3751 if (
x==0 ||
x==nx2*2-2 || (cen>(*binary)(
x+2,
y) || cen>(*binary)(
x-2,
y) || cen>(*binary)(
x,
y+1) || cen >(*binary)(
x,
y-1) || (*binary)(
x,
y)>rdist[r])) {
3752 image->set_value_at_fast(
x/2+nx2,
y,0.0);
3753 image->set_value_at_fast(nx2-
x/2,ny2*2-
y-1,0.0);
3756 image->set_value_at_fast(
x/2+nx2,
y,cen);
3757 image->set_value_at_fast(nx2-
x/2,ny2*2-
y-1,cen);
3761 image->set_value_at_fast(nx2+1,ny2,(*binary)(2,ny2));
3762 image->set_value_at_fast(nx2-1,ny2,(*binary)(2,ny2));
3763 image->set_value_at_fast(nx2,ny2+1,(*binary)(0,ny2+1));
3764 image->set_value_at_fast(nx2,ny2-1,(*binary)(0,ny2-1));
3765 for (
int y=0;
y<ny2*2;
y++) image->set_value_at_fast(0,
y,0.0f);
3768 float *idat=image->get_data();
3769 float *bdat=binary->get_data();
3770 int nxy=(nx2*ny2*4);
3771 for (
int i=0; i<nxy; i++) {
3772 bdat[i]=idat[i]==0?0:1.0f;
3777 image->set_complex(
false);
3778 binary->set_complex(
false);
3781 image->set_fftpad(
false);
3782 binary->set_fftpad(
false);
3785 image->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.04f));
3786 binary->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.04f));
3791 for (
int x=0;
x<image->get_xsize();
x+=2) {
3792 for (
int y=0;
y<image->get_ysize();
y++) {
3793 float bv=binary->get_value_at(
x/2+nx2,
y);
3794 image->set_value_at_fast(
x,
y,image->get_value_at(
x/2+nx2,
y)/(bv<=0?1.0f:bv));
3795 image->set_value_at_fast(
x+1,
y,0.0);
3798 image->set_complex(
true);
3799 image->set_fftpad(
true);
3800 image->process_inplace(
"xform.fourierorigin.tocorner");
3808#include <gsl/gsl_linalg.h>
3816 int nz = image->get_zsize();
3818 LOGERR(
"%s Processor doesn't support 3D model",
get_name().c_str());
3822 int nx = image->get_xsize();
3823 int ny = image->get_ysize();
3824 float *d = image->get_data();
3829 if (nx!=mask->get_xsize() || ny!=mask->get_ysize()) {
3830 LOGERR(
"%s Processor requires same size mask image",
get_name().c_str());
3833 dm = mask->get_data();
3837 for(
int i=0; i<nx*ny; i++) {
3845 LOGERR(
"%s Processor requires at least 3 pixels to fit a plane",
get_name().c_str());
3849 gsl_vector *S=gsl_vector_calloc(3);
3850 gsl_matrix *A=gsl_matrix_calloc(count,3);
3851 gsl_matrix *
V=gsl_matrix_calloc(3,3);
3853 double m[3] = {0, 0, 0};
3856 for(
int j=0; j<ny; j++){
3857 for(
int i=0; i<nx; i++){
3871 for(
int j=0; j<ny; j++){
3872 for(
int i=0; i<nx; i++){
3884 for(
int i=0; i<3; i++) m[i]/=count;
3888 for(
int j=0; j<ny; j++){
3889 for(
int i=0; i<nx; i++){
3893 gsl_matrix_set(A,index,0,i-m[0]);
3894 gsl_matrix_set(A,index,1,j-m[1]);
3895 gsl_matrix_set(A,index,2,d[ij]-m[2]);
3903 for(
int j=0; j<ny; j++){
3904 for(
int i=0; i<nx; i++){
3907 gsl_matrix_set(A,index,0,i-m[0]);
3908 gsl_matrix_set(A,index,1,j-m[1]);
3909 gsl_matrix_set(A,index,2,d[ij]-m[2]);
3916 gsl_linalg_SV_decomp_jacobi(A,
V, S);
3919 for(
int i=0; i<3; i++) n[i] = gsl_matrix_get(
V, i, 2);
3922 printf(
"S=%g,%g,%g\n",gsl_vector_get(S,0), gsl_vector_get(S,1), gsl_vector_get(S,2));
3923 printf(
"V[0,:]=%g,%g,%g\n",gsl_matrix_get(
V,0,0), gsl_matrix_get(
V,0,1),gsl_matrix_get(
V,0,2));
3924 printf(
"V[1,:]=%g,%g,%g\n",gsl_matrix_get(
V,1,0), gsl_matrix_get(
V,1,1),gsl_matrix_get(
V,1,2));
3925 printf(
"V[2,:]=%g,%g,%g\n",gsl_matrix_get(
V,2,0), gsl_matrix_get(
V,2,1),gsl_matrix_get(
V,2,2));
3926 printf(
"Fitted plane: p0=%g,%g,%g\tn=%g,%g,%g\n",m[0],m[1],m[2],n[0],n[1],n[2]);
3932 for(
int j=0; j<nx; j++){
3933 for(
int i=0; i<ny; i++){
3935 d[ij]-=
static_cast<float>(-((i-m[0])*n[0]+(j-m[1])*n[1])/n[2]+m[2]);
3940 for(
int j=0; j<nx; j++){
3941 for(
int i=0; i<ny; i++){
3943 if(d[ij]) d[ij]-=
static_cast<float>(-((i-m[0])*n[0]+(j-m[1])*n[1])/n[2]+m[2]);
3949 vector< float > planeParam;
3950 planeParam.resize(6);
3951 for(
int i=0; i<3; i++) planeParam[i] = static_cast<float>(n[i]);
3952 for(
int i=0; i<3; i++) planeParam[i+3] = static_cast<float>(m[i]);
3963 int nx = image->get_xsize();
3964 int ny = image->get_ysize();
3965 int nz = image->get_zsize();
3967 float *data = image->get_data();
3968 float sigma = image->get_attr(
"sigma");
3970 for (
int k = 0; k < nz; k++) {
3971 for (
int i = 0; i < nx; i++) {
3973 for (
int j = ny / 4; j < 3 * ny / 4; j++) {
3974 sum += data[i + j * nx];
3977 float mean = (float)sum / (ny / 2);
3978 for (
int j = 0; j < ny; j++) {
3979 data[i + j * nx] = (data[i + j * nx] - mean) / sigma;
3995 if(image->is_complex()) {
3996 LOGERR(
"%s Processor only operates on real images",
get_name().c_str());
4001 int nz = image->get_zsize();
4003 LOGERR(
"%s Processor doesn't support 3D models",
get_name().c_str());
4007 EMData *ff=image->do_fft();
4010 int nx=image->get_xsize();
4011 int ny=image->get_ysize();
4014 float norm=
static_cast<float>(nx*ny);
4016 for (
y=0;
y<ny;
y++) image->set_value_at(0,
y,0);
4018 for (
x=1;
x<nx/2;
x++) {
4019 for (
y=0;
y<ny;
y++) {
4021 if (
y<ny/2) y2=
y+ny/2;
4022 else if (
y==ny/2) y2=ny;
4024 image->set_value_at(
x,
y,ff->get_value_at(nx-
x*2,ny-y2)/norm);
4028 for (
x=nx/2;
x<nx;
x++) {
4029 for (
y=0;
y<ny;
y++) {
4031 if (
y<ny/2) y2=
y+ny/2;
4033 image->set_value_at(
x,
y,ff->get_value_at(
x*2-nx,y2)/norm);
4052 if (image->get_zsize() > 1) {
4053 LOGERR(
"%s Processor doesn't support 3D model",
get_name().c_str());
4059 float *d = image->get_data();
4063 int nx = image->get_xsize();
4064 int ny = image->get_ysize();
4066 float zval=9.99e23f;
4069 size_t corn=nx*ny-1;
4072 for (
x=1;
x<nx;
x++) {
if (d[
x]!=d[0])
break;}
4073 if (
x==nx) zval=d[0];
4075 for (
y=1;
y<ny;
y++) {
if (d[
y*nx]!=d[0])
break; }
4076 if (
y==ny) zval=d[0];
4078 for (
x=1;
x<nx;
x++) {
if (d[corn-
x]!=d[corn])
break;}
4079 if (
x==nx) zval=d[corn];
4081 for (
y=1;
y<ny;
y++) {
if (d[corn-
y*nx]!=d[corn])
break; }
4082 if (
y==ny) zval=d[corn];
4084 if (zval!=9.99e23f) {
4085 image->set_attr(
"hadzeroedge",1);
4089 else image->set_attr(
"hadzeroedge",0);
4092 for (
x=nx/2-5;
x<nx/2+5;
x++) {
4093 if (d[
x]!=d[
x+nx] || d[
x]!=d[
x+nx*2] )
break;
4095 if (
x==nx/2+5) image->set_attr(
"hadzeroedge",2);
4097 for (
x=nx/2-5;
x<nx/2+5;
x++) {
4098 if (d[corn-
x]!=d[corn-
x-nx] || d[corn-
x]!=d[corn-
x-nx*2])
break;
4100 if (
x==nx/2+5) image->set_attr(
"hadzeroedge",2);
4102 for (
y=ny/2-5;
y<ny/2+5;
y++) {
4103 if (d[
y*nx]!=d[
y*nx+1] || d[
y*nx]!=d[
y*nx+2] )
break;
4105 if (
y==ny/2+5) image->set_attr(
"hadzeroedge",2);
4107 for (
y=ny/2-5;
y<ny/2+5;
y++) {
4108 if (d[corn-
y*nx]!=d[corn-
y*nx-1] || d[corn-
y*nx]!=d[corn-
y*nx-2])
break;
4110 if (
y==ny/2+5) image->set_attr(
"hadzeroedge",2);
4113 if (zval==9.99e23f) zval=0;
4115 for (j = 0; j < ny; j++) {
4116 for (i = 0; i < nx - 1; i++) {
4117 if (d[i + j * nx] != zval) {
4122 float v = d[i + j * nx];
4128 for (i = nx - 1; i > 0; i--) {
4129 if (d[i + j * nx] != zval)
4139 for (i = 0; i < nx; i++) {
4140 for (j = 0; j < ny; j++) {
4141 if (d[i + j * nx] != zval)
4145 float v = d[i + j * nx];
4151 for (j = ny - 1; j > 0; j--) {
4152 if (d[i + j * nx] != zval)
4176 if (sigmamult<=0.0)
throw InvalidValueException(sigmamult,
"threshold.outlier.localmean: sigma must be >0");
4178 float hithr=(float)image->get_attr(
"mean")+(float)(image->get_attr(
"sigma"))*sigmamult;
4179 float lothr=(float)image->get_attr(
"mean")-(float)(image->get_attr(
"sigma"))*sigmamult;
4181 int nx=image->get_xsize();
4182 int ny=image->get_ysize();
4183 int nz=image->get_zsize();
4188 im[1]=image->copy_head();
4193 memcpy(im[1]->
get_data(),im[0]->
get_data(),image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
4195 for (
int y=0;
y<ny;
y++) {
4196 for (
int x=0;
x<nx;
x++) {
4198 float pix=im[1]->get_value_at(
x,
y);
4199 if (pix>hithr || pix<lothr || (pix==0 && fix_zero)) {
4201 int y1=
y>=ny-1?ny-1:
y+1;
4203 int x1=
x>=nx-1?nx-1:
x+1;
4204 float c=0.0f,nc=0.0f;
4205 for (
int yy=y0; yy<=y1; yy++) {
4206 for (
int xx=x0; xx<=x1; xx++) {
4207 float lpix=im[1]->get_value_at(xx,yy);
4208 if (lpix>hithr || lpix<lothr || (lpix==0 && fix_zero))
continue;
4213 if (nc!=0) im[0]->set_value_at(
x,
y,c/nc);
4233 if (image->get_zsize() > 1) {
4234 LOGERR(
"BeamstopProcessor doesn't support 3D model");
4238 float value1 =
params[
"value1"];
4239 float value2 =
params[
"value2"];
4240 float value3 =
params[
"value3"];
4242 float thr = fabs(value1);
4243 float *data = image->get_data();
4244 int cenx = (int) value2;
4245 int ceny = (int) value3;
4247 int nx = image->get_xsize();
4248 int ny = image->get_ysize();
4258 int mxr = (int) floor(
sqrt(2.0f) * nx / 2);
4260 float *mean_values =
new float[mxr];
4261 float *sigma_values =
new float[mxr];
4264 double square_sum = 0;
4266 for (
int i = 0; i < mxr; i++) {
4270 int nitems = 6 * i + 2;
4272 for (
int j = 0; j < nitems; j++) {
4273 float ang = j * 2 * M_PI / nitems;
4274 int x0 = (int) floor(cos(ang) * i + cenx);
4275 int y0 = (int) floor(sin(ang) * i + ceny);
4277 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
4281 float f = data[x0 + y0 * nx];
4283 square_sum += f * f;
4287 mean_values[i] = (float)sum / count;
4288 sigma_values[i] = (float)
sqrt(square_sum / count - mean_values[i] * mean_values[i]);
4292 for (
int k = 0; k < 5; k++) {
4293 for (
int i = 0; i < mxr; i++) {
4297 int nitems = 6 * i + 2;
4298 double thr1 = mean_values[i] - sigma_values[i] * thr;
4299 double thr2 = mean_values[i] + sigma_values[i];
4301 for (
int j = 0; j < nitems; j++) {
4302 float ang = j * 2 * M_PI / nitems;
4303 int x0 = (int) floor(cos(ang) * i + cenx);
4304 int y0 = (int) floor(sin(ang) * i + ceny);
4306 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
4307 data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
4311 sum += data[x0 + y0 * nx];
4312 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
4316 mean_values[i] = (float) sum / count;
4317 sigma_values[i] = (float)
sqrt(square_sum / count - mean_values[i] * mean_values[i]);
4321 for (
int i = 0; i < nx; i++) {
4322 for (
int j = 0; j < ny; j++) {
4324 int r =
Util::round(hypot((
float) i - cenx, (
float) j - ceny));
4327 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
4328 data[i + j * nx] = 0;
4331 data[i + j * nx] -= mean_values[r];
4335 if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
4338 data[i + j * nx] = mean_values[r];
4344 delete[]mean_values;
4350 delete[]sigma_values;
4365 if (image->get_zsize() > 1) {
4366 LOGERR(
"MeanZeroEdgeProcessor doesn't support 3D model");
4370 int nx = image->get_xsize();
4371 int ny = image->get_ysize();
4372 Dict dict = image->get_attr_dict();
4373 float mean_nonzero = dict.
get(
"mean_nonzero");
4375 float *d = image->get_data();
4379 for (j = 0; j < ny; j++) {
4380 for (i = 0; i < nx - 1; i++) {
4381 if (d[i + j * nx] != 0) {
4390 float v = d[i + j * nx] - mean_nonzero;
4394 d[i + j * nx] = v + mean_nonzero;
4399 for (i = nx - 1; i > 0; i--) {
4400 if (d[i + j * nx] != 0) {
4409 v = d[i + j * nx] - mean_nonzero;
4413 d[i + j * nx] = v + mean_nonzero;
4419 for (i = 0; i < nx; i++) {
4420 for (j = 0; j < ny; j++) {
4421 if (d[i + j * nx] != 0)
4425 float v = d[i + j * nx] - mean_nonzero;
4429 d[i + j * nx] = v + mean_nonzero;
4433 for (j = ny - 1; j > 0; j--) {
4434 if (d[i + j * nx] != 0)
4438 v = d[i + j * nx] - mean_nonzero;
4442 d[i + j * nx] = v + mean_nonzero;
4459 float *data = image->get_data();
4460 int nx = image->get_xsize();
4461 int ny = image->get_ysize();
4462 int nz = image->get_zsize();
4463 size_t nxy = (size_t)nx * ny;
4466 for (
int z = 0; z < nz; z++) {
4467 for (
int x = 0;
x < nx;
x++) {
4469 for (
int y = 0;
y < ny;
y++) {
4470 idx =
x +
y * nx + z * nxy;
4473 float mean = (float) sum / ny;
4475 for (
int y = 0;
y < ny;
y++) {
4476 idx =
x +
y * nx + z * nxy;
4492 int nx = image->get_xsize();
4493 int ny = image->get_ysize();
4495 float *d = image->get_data();
4496 int width =
params[
"width"];
4498 if (width > min(nx,ny)/2.){
4499 LOGERR(
"width parameter cannot be greater than min(nx,ny)/2");
4503 if (image->get_zsize() > 1){
4504 for (
int k=0; k<image->get_zsize(); k++){
4506 for (
int i=0; i<width; i++) {
4507 float frac=i/(float)width;
4508 for (
int j=0; j<nx; j++) {
4509 d[zidx+j+i*nx]*=frac;
4510 d[zidx+nx*ny-j-i*nx-1]*=frac;
4512 for (
int j=0; j<ny; j++) {
4513 d[zidx+j*nx+i]*=frac;
4514 d[zidx+nx*ny-j*nx-i-1]*=frac;
4521 for (
int i=0; i<width; i++) {
4522 float frac=i/(float)width;
4523 for (
int j=0; j<nx; j++) {
4525 d[nx*ny-j-i*nx-1]*=frac;
4527 for (
int j=0; j<ny; j++) {
4529 d[nx*ny-j*nx-i-1]*=frac;
4544 if (image->get_zsize() > 1) {
4545 LOGERR(
"ZeroEdgeRowProcessor is not supported in 3D models");
4549 int nx = image->get_xsize();
4550 int ny = image->get_ysize();
4552 float *d = image->get_data();
4564 size_t row_size = nx *
sizeof(float);
4566 memset(d, 0, top_nrows * row_size);
4567 memset(d + (ny - bottom_nrows) * nx, 0, bottom_nrows * row_size);
4569 for (
int i = top_nrows; i < ny - bottom_nrows; i++) {
4570 memset(d + i * nx, 0, left_ncols *
sizeof(
float));
4571 memset(d + i * nx + nx - right_ncols, 0, right_ncols *
sizeof(
float));
4583 if (image->get_zsize() <= 1) {
4584 LOGERR(
"ZeroEdgePlaneProcessor only support 3D models");
4588 int nx = image->get_xsize();
4589 int ny = image->get_ysize();
4590 int nz = image->get_zsize();
4592 float *d = image->get_data();
4601 size_t row_size = nx *
sizeof(float);
4602 size_t nxy = nx * ny;
4603 size_t sec_size = nxy *
sizeof(float);
4604 size_t y0row = y0 * row_size;
4605 size_t y1row = y1 * row_size;
4607 size_t x0size = x0*
sizeof(float);
4608 size_t x1size = x1*
sizeof(float);
4610 memset(d,0,z0*sec_size);
4611 memset(d+(nxy*(nz-z1)),0,sec_size*z1);
4613 for (
int z=z0; z<nz-z1; z++) {
4614 memset(d+z*nxy,0,y0row);
4615 memset(d+z*nxy+(ny-y1)*nx,0,y1row);
4618 int znxy2 = znxy + nx - x1;
4620 for (
int y=y0;
y<max_y;
y++) {
4621 memset(d+znxy+
y*nx,0,x0size);
4622 memset(d+znxy2+
y*nx,0,x1size);
4632 return image->get_attr(
"sigma");
4638 LOGWARN(
"cannot do normalization on NULL image");
4642 if (image->is_complex()) {
4643 LOGWARN(
"cannot do normalization on complex image");
4649 LOGWARN(
"cannot do normalization on image with sigma = 0");
4655 size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize();
4656 float *data = image->get_data();
4658 for (
size_t i = 0; i < size; ++i) {
4659 data[i] = (data[i] - mean) / sigma;
4671 float ret=
sqrt((
float)image->get_attr(
"square_sum"));
4672 return ret==0.0f?1.0f:ret;
4681 float ret=(float)image->get_attr(
"mean")*image->get_xsize()*image->get_ysize()*image->get_zsize();
4682 return ret==0.0f?1.0f:ret;
4695 int nx=image->get_xsize();
4696 int ny=image->get_ysize();
4697 int nz=image->get_zsize();
4703 for (
int z=0; z<nz; z++) {
4704 for (
int y=0;
y<ny;
y++) {
4705 for (
int x=0;
x<nx;
x++) {
4706 double m=mask->get_value_at(
x,
y,z);
4708 if (!apply_mask) m=1.0;
4709 double v=(double)image->get_value_at(
x,
y,z)*m;
4717 float mean=(float)(sum/nnz);
4718 float sigma=
sqrt((
float)(sumsq-sum*sum/nnz)/nnz);
4719 if (no_sigma) sigma=1.0f;
4721 for (
int z=0; z<nz; z++) {
4722 for (
int y=0;
y<ny;
y++) {
4723 for (
int x=0;
x<nx;
x++) {
4724 float m=mask->get_value_at(
x,
y,z);
4725 if (!apply_mask) m=1.0;
4726 if (m==0) image->set_value_at(
x,
y,z,0);
4727 else image->set_value_at(
x,
y,z,(image->get_value_at(
x,
y,z)*m-mean)/sigma);
4736 LOGWARN(
"cannot do normalization on NULL image");
4740 if (image->is_complex()) {
4741 LOGWARN(
"cannot do normalization on complex image");
4745 image->process_inplace(
"filter.ramp" );
4746 int nx = image->get_xsize();
4748 mask.process_inplace(
"testimage.circlesphere",
Dict(
"radius",nx/2-2,
"fill",1));
4750 vector<float> rstls = Util::infomask( image, &mask,
false);
4751 image->add((
float)-rstls[0]);
4752 image->mult((
float)1.0/rstls[1]);
4763 float tthr =
params.
set_default(
"thr",(
float)image->get_attr(
"mean")+(
float)image->get_attr(
"sigma"));
4765 float apix = image->get_attr_default(
"apix_x",1.0f);
4770 float step = ((float)image->get_attr(
"sigma"))/5.0f;
4775 size_t n = image->get_size();
4776 float* d = image->get_data();
4779 float thr=(float)image->get_attr(
"mean")+(float)image->get_attr(
"sigma")/2.0;
4781 for (
size_t i=0; i<n; ++i) {
4782 if (d[i]>=thr) ++count;
4784 if (verbose) printf(
"apix=%1.3f\tmass=%1.1f\tthr=%1.2f\tstep=%1.3g\n",apix,mass,thr,step);
4786 float max = image->get_attr(
"maximum");
4787 float min = image->get_attr(
"minimum");
4788 for (
int j=0; j<4; j++) {
4790 while (thr<max && count*apix*apix*apix*.81/1000.0>mass) {
4793 for (
size_t i=0; i<n; ++i) {
4794 if (d[i]>=thr) ++count;
4798 if (verbose>1) printf(
"%d\t%d\t%1.3f\t%1.2f\n",err,count,thr,count*apix*apix*apix*.81/1000.0);
4803 while (thr>min && count*apix*apix*apix*.81/1000.0<mass) {
4806 for (
size_t i=0; i<n; ++i) {
4807 if (d[i]>=thr) ++count;
4811 if (verbose>1) printf(
"%d\t%d\t%1.3f\t%1.2f\n",err,count,thr,count*apix*apix*apix*.81/1000.0);
4818 if ((
float)tthr/thr>0) image->mult((
float)tthr/thr);
4819 else printf(
"WARNING: could not normalize map to specified mass.");
4829 return image->get_edge_mean();
4839 int nx=image->get_xsize();
4840 int ny=image->get_ysize();
4841 int nz=image->get_zsize();
4845 if (radius<0) radius=ny/2+radius;
4847 static bool busy =
false;
4849 static int oldradius=radius;
4850 static int oldwidth=width;
4858 mask->set_size(nx, ny, nz);
4861 mask->process_inplace(
"mask.sharp",
Dict(
"inner_radius", radius,
4862 "outer_radius", radius + width));
4867 float *d = mask->get_data();
4868 float * data = image->get_data();
4869 size_t size = (size_t)nx*ny*nz;
4870 for (
size_t i = 0; i < size; ++i) {
4871 if (d[i]!=0.0f) { n+=1.0; s+=data[i]; }
4874 float result = (float)(s/n);
4888 float maxval = image->get_attr(
"maximum");
4889 float minval = image->get_attr(
"minimum");
4890 return (maxval + minval) / 2;
4899 float maxval = image->get_attr(
"maximum");
4900 float minval = image->get_attr(
"minimum");
4901 return (maxval - minval) / 2;
4911 int nx = image->get_xsize();
4912 int ny = image->get_ysize();
4913 int nz = image->get_zsize();
4914 float *d = image->get_data();
4915 size_t nyz = ny * nz;
4917 for (
size_t i = 0; i < nyz; i++) {
4919 size_t r = l + nx - 2;
4920 sum += d[l] + d[l + 1] + d[r] + d[r + 1];
4922 float mean = (float) sum / (4 * nyz);
4936 float *
rdata = image->get_data();
4937 int nx = image->get_xsize();
4938 int ny = image->get_ysize();
4939 int nz = image->get_zsize();
4944 for (
int z = 0; z < nz; z++) {
4947 for (
int y = 0;
y < ny;
y++) {
4948 for (
int x = 0;
x < nx;
x++) {
4949 float d =
rdata[
x +
y * nx + z*nx*ny];
4955 double row_mean = row_sum / nx / ny;
4956 double row_std = row_sqr / nx / ny;
4957 row_std =
sqrt(row_std - row_mean*row_mean);
4958 for (
int y = 0;
y < ny;
y++) {
4959 for (
int x = 0;
x < nx;
x++) {
4960 rdata[
x +
y * nx+ z*nx*ny] -= (float)row_mean;
4961 rdata[
x +
y * nx+ z*nx*ny] /= (float)row_std;
4974 for (
int y = 0;
y < ny;
y++) {
4976 for (
int x = 0;
x < nx;
x++) {
4977 row_len += pow((
double)
rdata[
x +
y * nx],2.0);
4979 row_len=
sqrt(row_len);
4980 if (row_len==0) row_len=1.0;
4982 for (
int x = 0;
x < nx;
x++) {
4983 rdata[
x +
y * nx] /= (float)row_len;
4990 for (
int y = 0;
y < ny;
y++) {
4992 for (
int x = 0;
x < nx;
x++) {
4996 double row_mean = row_sum / nx;
4997 if (row_mean <= 0) {
5001 for (
int x = 0;
x < nx;
x++) {
5002 rdata[
x +
y * nx] /= (float)row_mean;
5015 return image->get_attr(
"mean");
5024 float mean = image->get_attr(
"mean");
5025 float sig = image->get_attr(
"sigma");
5026 size_t n=image->get_size();
5029 int hist_size = image->get_size()/100;
5030 if (hist_size>1000) hist_size=1000;
5031 if (hist_size<5) hist_size=5;
5032 vector<float> hist(hist_size,0.0f);
5034 float histmin=mean-2.0f*sig;
5035 float histmax=mean+2.0f*sig;
5036 float step=(histmax-histmin)/(hist_size-1);
5037 for (
size_t i=0; i<n; i++) {
5038 int bin = (image->get_value_at_index(i)-histmin)/step;
5039 bin=bin<0?0:(bin>=hist_size?hist_size-1:bin);
5044 int maxv=hist[1],maxn=1;
5045 for (
int i=2; i<hist_size-1; i++) {
5046 if (hist[i]>maxv) { maxv=hist[i]; maxn=i; }
5050 float v1=hist[maxn-1],v2=hist[maxn],v3=hist[maxn+1];
5051 float ret= (v1*(maxn-1)+v2*maxn+v3*(maxn+1))/(v1+v2+v3)*step+histmin;
5052 printf(
"%f %f %f %f %f %f\n",v1,v2,v3,mean,sig,ret);
5074 int si0=(int)floor(
params.
set_default(
"low_cutoff_frequency",0.0f)*image->get_ysize());
5075 int si1=(int)ceil(
params.
set_default(
"high_cutoff_frequency",0.7071f)*image->get_ysize());
5079 if (image->is_complex()) imf=image->copy();
5080 else imf=image->do_fft();
5083 EMData *ctfi=imf->copy_head();
5086 ctf=(
Ctf *)(image->get_attr(
"ctf"));
5094 if (refr->is_complex()) ref=refr;
5095 else ref=refr->do_fft();
5098 if (actual==NULL) actf=ref;
5100 if (ctfweight)
throw InvalidCallException(
"math.sub.optimal: Sorry, cannot use ctfweight in combination with actual");
5101 if (actual->is_complex()) actf=actual;
5102 else actf=actual->do_fft();
5105 int ny2=(int)(image->get_ysize()*
sqrt(2.0)/2);
5106 vector <double>rad(ny2+1);
5107 vector <double>norm(ny2+1);
5112 for (
int y=-ny2;
y<ny2;
y++) {
5113 for (
int x=0;
x<ny2;
x++) {
5115 if (r>ny2)
continue;
5116 std::complex<float> v1=imf->get_complex_at(
x,
y);
5117 std::complex<float> v2=ref->get_complex_at(
x,
y);
5118 rad[r]+=(double)(v1.real()*v2.real()+v1.imag()*v2.imag());
5120 norm[r]+=(double)(v2.real()*v2.real()+v2.imag()*v2.imag());
5123 for (
int i=1; i<ny2; i++) rad[i]/=norm[i];
5132 if (return_presigma) {
5133 for (
int y=-ny2;
y<ny2;
y++) {
5134 for (
int x=0;
x<imf->get_xsize()/2;
x++) {
5136 if (r>=ny2 || r>=si1 || r<si0) {
5137 imf->set_complex_at(
x,
y,0);
5140 std::complex<float> v1=imf->get_complex_at(
x,
y);
5141 imf->set_complex_at(
x,
y,v1);
5144 EMData *tmp=imf->do_ift();
5145 oldsig=(float)tmp->get_attr(
"sigma");
5149 for (
int y=-ny2;
y<ny2;
y++) {
5150 for (
int x=0;
x<imf->get_xsize()/2;
x++) {
5152 if (r>=ny2 || r>=si1 || r<si0) {
5153 imf->set_complex_at(
x,
y,0);
5156 std::complex<float> v1=imf->get_complex_at(
x,
y);
5157 std::complex<float> v2=actf->get_complex_at(
x,
y);
5159 if (return_subim) imf->set_complex_at(
x,
y,v2);
5160 else imf->set_complex_at(
x,
y,v1-v2);
5164 if (!refr->is_complex())
delete ref;
5165 if (actual!=NULL && !actual->is_complex())
delete actf;
5168 if (return_radial) {
5170 for (
int i=0; i<ny2; i++) radf[i]=(
float)rad[i];
5174 EMData *ret=imf->do_ift();
5176 if (return_radial) ret->set_attr(
"filter_curve",radf);
5177 if (return_presigma) {
5178 ret->set_attr(
"sigma_presub",oldsig);
5183 if (return_radial) imf->set_attr(
"filter_curve",radf);
5184 if (return_presigma) imf->set_attr(
"sigma_presub",oldsig);
5196 memcpy(image->get_data(),tmp->get_data(),(
size_t)image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
5219 int nx = image->get_xsize();
5220 int ny = image->get_ysize();
5221 int nz = image->get_zsize();
5222 size_t size = (size_t)nx * ny * nz;
5231 float meani=(float)image->get_attr(
"mean");
5232 float meant=(float)to->get_attr(
"mean");
5233 float sigi=(float)image->get_attr(
"sigma")*ignore_lowsig;
5234 float sigt=(float)to->get_attr(
"sigma")*ignore_lowsig;
5237 fim=image->do_fft();
5241 dimage=fim->get_data();
5242 dto=fto->get_data();
5244 size2=(size_t)(nx+2) * ny * nz;
5249 for (
size_t i=0; i<size2; i+=2) { sigi+=pow(dimage[i],2.0f); sigt+=pow(dto[i],2.0f); }
5250 sigi=ignore_lowsig*
sqrt(sigi/(size2/2));
5251 sigt=ignore_lowsig*
sqrt(sigt/(size2/2));
5254 dimage = image->get_data();
5255 dto = to->get_data();
5262 if (ignore_lowsig<0) ignore_lowsig=0;
5265 for (
size_t i = 0; i < size2; i+=step) {
5266 if (dto[i] >= low_threshold && dto[i] <= high_threshold
5267 && (dto[i]>=meant+sigt || dto[i]<=meant-sigt)
5268 && (dimage[i]>=meani+sigi || dimage[i]<=meani-sigi)
5269 && (!ignore_zero ||(dto[i] != 0.0f && dimage[i] != 0.0f))) {
5275 double *
x=(
double *)malloc(count*
sizeof(
double));
5276 double *
y=(
double *)malloc(count*
sizeof(
double));
5278 for (
size_t i = 0; i < size2; i+=step) {
5279 if (dto[i] >= low_threshold && dto[i] <= high_threshold
5280 && (dto[i]>=meant+sigt || dto[i]<=meant-sigt)
5281 && (dimage[i]>=meani+sigi || dimage[i]<=meani-sigi)
5282 && (!ignore_zero ||(dto[i] != 0.0f && dimage[i] != 0.0f))) {
5289 double cov00,cov01,cov11,sumsq;
5290 gsl_fit_linear (
x, 1,
y, 1, count, &c0, &c1, &cov00, &cov01, &cov11, &sumsq);
5293 FILE*out=fopen(
"debug.txt",
"w");
5294 for (
size_t i = 0; i < count; i++) {
5295 fprintf(out,
"%lf\t%lf\n",
x[i],
y[i]);
5298 printf(
"add %lf\tmul %lf\t%lf\t%lf\t%lf\t%lf\n",c0,c1,cov00,cov01,cov11,sumsq);
5303 if (fim!=NULL)
delete fim;
5304 if (fto!=NULL)
delete fto;
5306 if (fourieramp) c0=0;
5307 dimage = image->get_data();
5308 for (
size_t i = 0; i < size; ++i) dimage[i]=dimage[i]*c1+c0;
5310 image->set_attr(
"norm_mult",c1);
5311 image->set_attr(
"norm_add",c0);
5316 if (!image->is_complex())
throw ImageFormatException(
"Fourier binary thresholding processor only works for complex images");
5321 float* d = image->get_data();
5322 for(
size_t i = 0; i < image->get_size()/2; ++i, d+=2) {
5323 if ( *d < threshold ) {
5329 image->set_ri(
true);
5341 float distance_sigma =
params[
"distance_sigma"];
5342 float value_sigma =
params[
"value_sigma"];
5343 int max_iter =
params[
"niter"];
5344 int half_width =
params[
"half_width"];
5346 if (half_width < distance_sigma) {
5347 LOGWARN(
"localwidth(=%d) should be larger than distance_sigma=(%f)\n",
5348 half_width, distance_sigma);
5351 distance_sigma *= distance_sigma;
5353 float image_sigma = image->get_attr(
"sigma");
5354 if (image_sigma > value_sigma) {
5355 LOGWARN(
"image sigma(=%f) should be smaller than value_sigma=(%f)\n",
5356 image_sigma, value_sigma);
5358 value_sigma *= value_sigma;
5360 int nx = image->get_xsize();
5361 int ny = image->get_ysize();
5362 int nz = image->get_zsize();
5365 int width=nx, height=ny;
5369 float tempfloat1,tempfloat2,tempfloat3;
5370 int index1,index2,index;
5372 int tempint1,tempint3;
5375 tempint3=width+2*half_width;
5377 float* mask=(
float*)calloc((2*half_width+1)*(2*half_width+1),
sizeof(
float));
5378 float* OrgImg=(
float*)calloc((2*half_width+width)*(2*half_width+height),
sizeof(
float));
5379 float* NewImg=image->get_data();
5381 for(m=-(half_width);m<=half_width;m++)
5382 for(n=-(half_width);n<=half_width;n++) {
5383 index=(m+half_width)*(2*half_width+1)+(n+half_width);
5384 mask[index]=exp((
float)(-(m*m+n*n)/distance_sigma/2.0));
5390 while(Iter<max_iter) {
5391 for(i=0;i<height;i++)
5392 for(j=0;j<width;j++) {
5393 index1=(i+half_width)*tempint3+(j+half_width);
5394 index2=i*tempint1+j;
5395 OrgImg[index1]=NewImg[index2];
5399 for(i=0;i<height;i++){
5400 for(j=0;j<half_width;j++) OrgImg[(i+half_width)*tempint3+(j)]=OrgImg[(i+half_width)*tempint3+(2*half_width-j)];
5401 for(j=0;j<half_width;j++) OrgImg[(i+half_width)*tempint3+(j+width+half_width)]=OrgImg[(i+half_width)*tempint3+(width+half_width-j-2)];
5403 for(i=0;i<half_width;i++){
5404 for(j=0;j<(width+2*half_width);j++) OrgImg[i*tempint3+j]=OrgImg[(2*half_width-i)*tempint3+j];
5405 for(j=0;j<(width+2*half_width);j++) OrgImg[(i+height+half_width)*tempint3+j]=OrgImg[(height+half_width-2-i)*tempint3+j];
5411 for(i=0;i<height;i++){
5413 for(j=0;j<width;j++){
5414 tempfloat1=0.0; tempfloat2=0.0;
5415 for(m=-(half_width);m<=half_width;m++)
5416 for(n=-(half_width);n<=half_width;n++){
5417 index =(m+half_width)*(2*half_width+1)+(n+half_width);
5418 index1=(i+half_width)*tempint3+(j+half_width);
5419 index2=(i+half_width+m)*tempint3+(j+half_width+n);
5420 tempfloat3=(OrgImg[index1]-OrgImg[index2])*(OrgImg[index1]-OrgImg[index2]);
5422 tempfloat3=mask[index]*(1.0f/(1+tempfloat3/value_sigma));
5424 tempfloat1+=tempfloat3;
5426 tempfloat2+=tempfloat3*OrgImg[(i+half_width+m)*tempint3+(j+half_width+n)];
5428 NewImg[i*width+j]=tempfloat2/tempfloat1;
5446 int slice_size = width * height;
5447 int new_width = width + 2 * half_width;
5448 int new_slice_size = (width + 2 * half_width) * (height + 2 * half_width);
5450 int width1 = 2 * half_width + 1;
5451 int mask_size = width1 * width1;
5452 int old_img_size = (2 * half_width + width) * (2 * half_width + height);
5454 int zstart = -half_width;
5455 int zend = -half_width;
5458 mask_size *= width1;
5459 old_img_size *= (2 * half_width + slicenum);
5464 float *mask = (
float *) calloc(mask_size,
sizeof(
float));
5465 float *old_img = (
float *) calloc(old_img_size,
sizeof(
float));
5467 float *new_img = image->get_data();
5469 for (
int p = zstart; p <= zend; p++) {
5470 int cur_p = (p + half_width) * (2 * half_width + 1) * (2 * half_width + 1);
5472 for (
int m = -half_width; m <= half_width; m++) {
5473 int cur_m = (m + half_width) * (2 * half_width + 1) + half_width;
5475 for (
int n = -half_width; n <= half_width; n++) {
5476 int l = cur_p + cur_m + n;
5477 mask[l] = exp((
float) (-(m * m + n * n + p * p * is_3d) / distance_sigma / 2.0f));
5483 while (iter < max_iter) {
5484 for (
int k = 0; k < slicenum; k++) {
5485 size_t cur_k1 = (size_t)(k + half_width) * new_slice_size * is_3d;
5486 int cur_k2 = k * slice_size;
5488 for (
int i = 0; i < height; i++) {
5489 int cur_i1 = (i + half_width) * new_width;
5490 int cur_i2 = i * width;
5492 for (
int j = 0; j < width; j++) {
5493 size_t k1 = cur_k1 + cur_i1 + (j + half_width);
5494 int k2 = cur_k2 + cur_i2 + j;
5495 old_img[k1] = new_img[k2];
5500 for (
int k = 0; k < slicenum; k++) {
5501 size_t cur_k = (k + half_width) * new_slice_size * is_3d;
5503 for (
int i = 0; i < height; i++) {
5504 int cur_i = (i + half_width) * new_width;
5506 for (
int j = 0; j < half_width; j++) {
5507 size_t k1 = cur_k + cur_i + j;
5508 size_t k2 = cur_k + cur_i + (2 * half_width - j);
5509 old_img[k1] = old_img[k2];
5512 for (
int j = 0; j < half_width; j++) {
5513 size_t k1 = cur_k + cur_i + (width + half_width + j);
5514 size_t k2 = cur_k + cur_i + (width + half_width - j - 2);
5515 old_img[k1] = old_img[k2];
5520 for (
int i = 0; i < half_width; i++) {
5521 int i2 = i * new_width;
5522 int i3 = (2 * half_width - i) * new_width;
5523 for (
int j = 0; j < (width + 2 * half_width); j++) {
5524 size_t k1 = cur_k + i2 + j;
5525 size_t k2 = cur_k + i3 + j;
5526 old_img[k1] = old_img[k2];
5529 i2 = (height + half_width + i) * new_width;
5530 i3 = (height + half_width - 2 - i) * new_width;
5531 for (
int j = 0; j < (width + 2 * half_width); j++) {
5532 size_t k1 = cur_k + i2 + j;
5533 size_t k2 = cur_k + i3 + j;
5534 old_img[k1] = old_img[k2];
5540 for (
int k = 0; k < slicenum; k++) {
5541 size_t cur_k = (k + half_width) * new_slice_size;
5543 for (
int i = 0; i < height; i++) {
5544 int cur_i = (i + half_width) * new_width;
5546 for (
int j = 0; j < width; j++) {
5549 size_t k1 = cur_k + cur_i + (j + half_width);
5551 for (
int p = zstart; p <= zend; p++) {
5552 size_t cur_p1 = (p + half_width) * (2 * half_width + 1) * (2 * half_width + 1);
5553 size_t cur_p2 = (k + half_width + p) * new_slice_size;
5555 for (
int m = -half_width; m <= half_width; m++) {
5556 size_t cur_m1 = (m + half_width) * (2 * half_width + 1);
5557 size_t cur_m2 = cur_p2 + cur_i + m * new_width + j + half_width;
5559 for (
int n = -half_width; n <= half_width; n++) {
5560 size_t k = cur_p1 + cur_m1 + (n + half_width);
5561 size_t k2 = cur_m2 + n;
5564 f3 = mask[k] * (1.0f / (1 + f3 / value_sigma));
5566 size_t l1 = cur_m2 + n;
5567 f2 += f3 * old_img[l1];
5570 idx = (size_t)k * height * width + i * width + j;
5571 new_img[idx] = f2 / f1;
5597 int isinten=image->get_attr_default(
"is_intensity",0);
5598 if (!image || ((image->is_complex() && image->get_ndim() > 2))){
5599 LOGWARN(
"only works on real or 2D intensity images. do nothing.");
5603 if (image->get_ndim() <= 0 || image->get_ndim() > 3)
throw ImageDimensionException(
"radial average processor only works for real and 2D intensity images");
5605 float *
rdata = image->get_data();
5606 int nx = image->get_xsize();
5607 int ny = image->get_ysize();
5611 if ((!image->is_complex()) && (isinten == 1)) {
5612 std::reverse(dist.begin(),dist.end());
5615 float midx = (float)((
int)nx/2);
5616 float midy = (float)((
int)ny/2);
5619 if (image->is_complex() && image->get_ndim() == 2) {
5620 for (
int y = -ny/2;
y < ny/2;
y++) {
5621 for (
int x = -ny/2-1;
x < nx/2+1;
x++) {
5622 float r = (float) hypot(
x,
y);
5623 int i = (int) floor(r);
5625 if (i >= 0 && i < nx / 2 - 1) {
5626 image->set_complex_at(
x,
y, dist[i] * (1.0f - r) + dist[i + 1] * r);
5629 image->set_complex_at(
x,
y, dist[0]);
5632 image->set_complex_at(
x,
y, 0);
5637 else if (image->get_ndim() == 2) {
5638 for (
int y = 0;
y < ny;
y++) {
5639 for (
int x = 0;
x < nx;
x++, c++) {
5640 float r = (float) hypot(
x - midx,
y - midy);
5642 int i = (int) floor(r);
5644 if (i >= 0 && i < nx / 2 - 1) {
5645 rdata[c] = dist[i] * (1.0f - r) + dist[i + 1] * r;
5656 else if (image->get_ndim() == 3) {
5657 int nz = image->get_zsize();
5658 float midz = (float)((
int)nz/2);
5661 for (
int z = 0; z < nz; ++z) {
5662 for (
int y = 0;
y < ny; ++
y) {
5663 for (
int x = 0;
x < nx; ++
x, ++c) {
5669 if (i >= 0 && i < nx / 2 - 1) {
5670 rdata[c] = dist[i] * (1.0f - r) + dist[i + 1] * r;
5690 if (!image || image->is_complex()) {
5691 LOGWARN(
"only works on real image. do nothing.");
5697 float *
rdata = image->get_data();
5698 int nx = image->get_xsize();
5699 int ny = image->get_ysize();
5704 for (
int y = 0;
y < ny;
y++) {
5705 for (
int x = 0;
x < nx;
x++, c++) {
5706 float r = (float) hypot(
x - nx / 2,
y - ny / 2);
5707 int i = (int) floor(r);
5709 if (i >= 0 && i < nx / 2 - 1) {
5710 rdata[c] -= dist[i] * (1.0f - r) + dist[i + 1] * r;
5726 EMData* ret =
new EMData(image->get_ysize(),image->get_xsize(),1);
5728 for(
int j = 0; j< image->get_ysize();++j) {
5729 for(
int i = 0; i< image->get_xsize();++i) {
5730 ret->set_value_at(j,i,image->get_value_at(i,j));
5742 float* data = (
float*)malloc(image->get_ysize()*image->get_xsize()*
sizeof(float));
5744 int nx = image->get_ysize();
5745 for(
int j = 0; j< image->get_ysize();++j) {
5746 for(
int i = 0; i< image->get_xsize();++i) {
5747 data[i*nx+j] = image->get_value_at(i,j);
5751 image->set_data(data,image->get_ysize(),image->get_xsize(),1);
5762 string axis = (
const char*)
params[
"axis"];
5764#ifdef EMAN2_USING_CUDA
5765 if (EMData::usecuda == 1 && image->getcudarwdata()) {
5767 float array[12] = {1.0, 0.0, 0.0, 0.0,
5769 0.0, 0.0, 1.0, 0.0};
5770 if (axis ==
"x" || axis ==
"X") {
5772 }
else if (axis ==
"y" || axis ==
"Y") {
5775 else if (axis ==
"z" || axis ==
"Z") {
5780 image->process_inplace(
"xform",
params);
5788 float *d = image->get_data();
5789 int nx = image->get_xsize();
5790 int ny = image->get_ysize();
5791 int nz = image->get_zsize();
5793 size_t nxy = nx * ny;
5800 if (axis ==
"x" || axis ==
"X") {
5801 int offset = (nx%2 == 0);
5803 for(
int z = 0; z < nz; ++z) {
5804 for(
int y = 0;
y < ny; ++
y) {
5806 idx1 = z*nxy +
y*nx;
5809 for(
int x = offset;
x < nx / 2; ++
x) {
5810 idx1 = z*nxy +
y*nx +
x;
5811 idx2 = z*nxy +
y*nx + (nx-
x-1+offset);
5812 std::swap(d[idx1], d[idx2]);
5819 else if (axis ==
"y" || axis ==
"Y") {
5820 int offset = (ny%2 == 0);
5821 for(
int z=0; z<nz; ++z) {
5823 std::fill(d+z*nxy,d+(
size_t)z*nxy+nx,0);
5825 for(
int y=offset;
y<ny/2; ++
y) {
5826 for(
int x=0;
x<nx; ++
x) {
5827 std::swap(d[(
size_t)z*nxy +
y*nx +
x], d[(
size_t)z*nxy + (ny -
y -1+offset)*nx +
x]);
5832 else if (axis ==
"z" || axis ==
"Z") {
5833 int offset = (nz%2 == 0);
5835 std::fill(d,d+nxy,0);
5838 for(
int z=offset; z<nz/2; ++z) {
5839 for(
int y=0;
y<ny; ++
y) {
5840 for(
int x=0;
x<nx; ++
x) {
5841 idx1 = (size_t)z*nxy +
y*nx +
x;
5842 idx2 = (size_t)(nz-z-1+offset)*nxy +
y*nx +
x;
5843 std::swap(d[idx1], d[idx2]);
5865 float addnoise =
params[
"noise"];
5867 float *dat = image->get_data();
5869 for (
size_t j = 0; j < image->get_size(); ++j) {
5882 return image->get_attr(
"sigma");
5887 if ( !image->is_complex() )
throw ImageFormatException(
"Can not Fourier origin shift an image that is not complex");
5889 int nx=image->get_xsize();
5890 int ny=image->get_ysize();
5891 int nz=image->get_zsize();
5895 if ( ny == 1 && nz == 1 ){
5896 cout <<
"Warning- attempted Fourier origin shift a 1D image - no action taken" << endl;
5899 int yodd = (ny%2==1);
5900 int zodd = (nz%2==1);
5902 float*
rdata = image->get_data();
5915 for(
int s = 0; s < nz; s++ ) {
5916 for(
int c =0; c < nx; c += 2 ) {
5917 idx = (size_t)s*nxy+ny/2*nx+c;
5918 prev[0] =
rdata[idx];
5919 prev[1] =
rdata[idx+1];
5920 for(
int r = 0; r <= ny/2; ++r ) {
5921 idx = (size_t)s*nxy+r*nx+c;
5922 float* p1 = &
rdata[idx];
5938 for(
int s = 0; s < nz; ++s ) {
5939 for(
int r = 0 + yodd; r < ny/2+yodd; ++r ) {
5940 for(
int c =0; c < nx; c += 2 ) {
5941 idx1 = (size_t)s*nxy+r*nx+c;
5942 idx2 = (size_t)s*nxy+(r+ny/2)*nx+c;
5967 for(
int r = 0; r < ny; ++r ) {
5968 for(
int c =0; c < nx; c += 2 ) {
5969 idx = (size_t)nz/2*nxy+r*nx+c;
5970 prev[0] =
rdata[idx];
5971 prev[1] =
rdata[idx+1];
5972 for(
int s = 0; s <= nz/2; ++s ) {
5973 idx = (size_t)s*nxy+r*nx+c;
5974 float* p1 = &
rdata[idx];
5990 for(
int s = 0+zodd; s < nz/2 + zodd; ++s ) {
5991 for(
int r = 0; r < ny; ++r ) {
5992 for(
int c =0; c < nx; c += 2 ) {
5993 idx1 = (size_t)s*nxy+r*nx+c;
5994 idx2 = (size_t)(s+nz/2)*nxy+r*nx+c;
6010 image->set_shuffled(
false);
6017 int nx=image->get_xsize();
6018 int ny=image->get_ysize();
6019 int nz=image->get_zsize();
6023 if ( ny == 1 && nz == 1 ){
6024 cout <<
"Warning- attempted Fourier origin shift a 1D image - no action taken" << endl;
6028 int yodd = (ny%2==1);
6029 int zodd = (nz%2==1);
6031 float*
rdata = image->get_data();
6039 if ( !image->is_complex() ) {
6040 if (nz!=1 && !yodd && !zodd) {
6041 for (
int x=0;
x<nx;
x++) {
6042 for (
int y=0;
y<ny;
y++) {
6043 for (
int z=0; z<nz/2; z++) {
6046 size_t i=
x+
y*nx+(size_t)z*nxy;
6047 size_t i2=
x+y2*nx+(size_t)z2*nxy;
6057 else throw ImageFormatException(
"Can not Fourier origin shift an image that is not complex unless it is even in ny,nz and nx=ny/2+1");
6065 for(
int s = 0; s < nz; s++ ) {
6066 for(
int c =0; c < nx; c += 2 ) {
6067 idx = (size_t)s*nxy+c;
6068 prev[0] =
rdata[idx];
6069 prev[1] =
rdata[idx+1];
6070 for(
int r = ny/2; r >= 0; --r ) {
6071 idx = (size_t)s*nxy+r*nx+c;
6072 float* p1 = &
rdata[idx];
6088 for(
int s = 0; s < nz; ++s ) {
6089 for(
int r = 0; r < ny/2; ++r ) {
6090 for(
int c =0; c < nx; c += 2 ) {
6091 idx1 = (size_t)s*nxy+r*nx+c;
6092 idx2 = (size_t)s*nxy+(r+ny/2+yodd)*nx+c;
6114 for(
int r = 0; r < ny; ++r ) {
6115 for(
int c =0; c < nx; c += 2 ) {
6116 prev[0] =
rdata[r*nx+c];
6117 prev[1] =
rdata[r*nx+c+1];
6118 for(
int s = nz/2; s >= 0; --s ) {
6119 idx = (size_t)s*nxy+r*nx+c;
6120 float* p1 = &
rdata[idx];
6136 for(
int s = 0; s < nz/2; ++s ) {
6137 for(
int r = 0; r < ny; ++r ) {
6138 for(
int c =0; c < nx; c += 2 ) {
6139 idx1 = (size_t)s*nxy+r*nx+c;
6140 idx2 = (size_t)(s+nz/2+zodd)*nxy+r*nx+c;
6156 image->set_shuffled(
true);
6161 if ( !image->is_complex() )
throw ImageFormatException(
"Can not handle images that are not complex in fourier phase shift 180");
6165 image->center_origin_fft();
6186 int nx = image->get_xsize();
6187 int ny = image->get_ysize();
6188 int nz = image->get_zsize();
6190 int xodd = (nx % 2) == 1;
6191 int yodd = (ny % 2) == 1;
6192 int zodd = (nz % 2) == 1;
6196 float *
rdata = image->get_data();
6198 if ( ny == 1 && nz == 1 ){
6201 else if ( nz == 1 ) {
6204 for (
int r = 0; r < ny/2; ++r ) {
6205 for (
int c = 0; c < nx/2; ++c) {
6206 int idx1 = r*nx + c;
6207 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd;
6208 float tmp =
rdata[idx1];
6215 for (
int r = ny-1; r >= (ny/2+yodd); --r ) {
6216 for (
int c = 0; c < nx/2; ++c) {
6217 int idx1 = r*nx + c;
6218 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd;
6219 float tmp =
rdata[idx1];
6231 for (
int s = 0; s < nz/2; ++s ) {
6232 for (
int r = 0; r < ny/2; ++r ) {
6233 for (
int c = 0; c < nx/2; ++ c) {
6234 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6235 idx2 = (s+nz/2+zodd)*(
size_t)nxy+(r+ny/2+yodd)*(
size_t)nx+c+nx/2+xodd;
6243 for (
int s = 0; s < nz/2; ++s ) {
6244 for (
int r = 0; r < ny/2; ++r ) {
6245 for (
int c = nx-1; c >= (nx/2+xodd); --c) {
6246 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6247 idx2 = (s+nz/2+zodd)*(
size_t)nxy+(r+ny/2+yodd)*(
size_t)nx+c-nx/2-xodd;
6255 for (
int s = 0; s < nz/2; ++s ) {
6256 for (
int r = ny-1; r >= (ny/2+yodd); --r ) {
6257 for (
int c = nx-1; c >= (nx/2+xodd); --c) {
6258 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6259 idx2 = (s+nz/2+zodd)*(
size_t)nxy+(r-ny/2-yodd)*(
size_t)nx+c-nx/2-xodd;
6267 for (
int s = 0; s < nz/2; ++s ) {
6268 for (
int r = ny-1; r >= (ny/2+yodd); --r ) {
6269 for (
int c = 0; c < nx/2; ++c) {
6270 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6271 idx2 = (s+nz/2+zodd)*(
size_t)nxy+(r-ny/2-yodd)*(
size_t)nx+c+nx/2+xodd;
6283 int nx = image->get_xsize();
6284 int ny = image->get_ysize();
6285 int nz = image->get_zsize();
6287 int xodd = (nx % 2) == 1;
6288 int yodd = (ny % 2) == 1;
6289 int zodd = (nz % 2) == 1;
6293 float *
rdata = image->get_data();
6295 if ( ny == 1 && nz == 1 ){
6298 else if ( nz == 1 ) {
6303 for (
int c = 0; c < nx/2; ++c ) {
6304 int idx1 = r*nx + c;
6305 int idx2 = r*nx + c + nx/2+ xodd;
6315 for (
int r = 0; r < ny/2; ++r ) {
6316 int idx1 = r*nx + c;
6317 int idx2 = (r+ny/2+yodd)*nx + c;
6331 for(
int s = 0; s < nz/2; ++s ) {
6332 for (
int r = 0; r < ny/2; ++r ) {
6333 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6334 idx2 = (s+nz/2+zodd)*(
size_t)nxy+(r+ny/2+yodd)*(
size_t)nx+c;
6341 for(
int s = nz-1; s >= (nz/2+zodd); --s ) {
6342 for (
int r = 0; r < ny/2; ++r ) {
6343 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6344 idx2 = (s-nz/2-zodd)*(
size_t)nxy+(r+ny/2+yodd)*(
size_t)nx+c;
6355 for(
int s = 0; s < nz/2; ++s ) {
6356 for (
int c = 0; c < nx/2; ++c ) {
6357 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6358 idx2 =(s+nz/2+zodd)*(
size_t)nxy+(size_t)r*nx+c+nx/2+xodd;
6365 for(
int s = nz-1; s >= (nz/2+zodd); --s ) {
6366 for (
int c = 0; c < nx/2; ++c ) {
6367 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6368 idx2 = (s-nz/2-zodd)*(
size_t)nxy+(size_t)r*nx+c+nx/2+xodd;
6379 for(
int r = 0; r < ny/2; ++r ) {
6380 for (
int c = 0; c < nx/2; ++c ) {
6381 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6382 idx2 = (size_t)s*nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd;
6389 for(
int r = ny-1; r >= (ny/2+yodd); --r ) {
6390 for (
int c = 0; c < nx/2; ++c ) {
6391 idx1 = (size_t)s*nxy+(
size_t)r*nx+c;
6392 idx2 = (size_t)s*nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd;
6406#ifdef EMAN2_USING_CUDA
6407 if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) {
6414 if (image->is_complex()) {
6419 int nx = image->get_xsize();
6420 int ny = image->get_ysize();
6421 int nz = image->get_zsize();
6423 if ( ny == 1 && nz == 1 && nx == 1)
return;
6427 float *
rdata = image->get_data();
6429 bool xodd = (nx % 2) == 1;
6430 bool yodd = (ny % 2) == 1;
6431 bool zodd = (nz % 2) == 1;
6433 if ( ny == 1 && nz == 1 ){
6437 float in_x =
rdata[nx-1];
6439 for (
int i = nx/2; i < nx; ++i ) {
6446 for (
int i = 0; i < nx/2; ++i ) {
6447 int idx = i+nx/2+xodd;
6448 float tmp =
rdata[i];
6454 else if ( nz == 1 ) {
6458 for (
int c = 0; c < nx; ++c ) {
6460 float last_val =
rdata[(ny-1)*nx + c];
6462 for (
int r = ny/2; r < ny; ++r ){
6465 rdata[idx] = last_val;
6474 for (
int r = 0; r < ny; ++r ) {
6475 float last_val =
rdata[(r+1)*nx -1];
6477 for (
int c = nx/2; c < nx; ++c ){
6480 rdata[idx] = last_val;
6498 for (
int r = 0; r < ny; ++r){
6499 for (
int c = 0; c < nx; ++c) {
6500 float last_val =
rdata[(nz-1)*nxy+r*nx+c];
6501 for (
int s = nz/2; s < nz; ++s) {
6502 idx = (size_t)s*nxy+r*nx+c;
6504 rdata[idx] = last_val;
6514 for (
int s = 0; s < nz; ++s) {
6515 for (
int c = 0; c < nx; ++c) {
6516 float last_val =
rdata[s*nxy+(ny-1)*nx+c];
6517 for (
int r = ny/2; r < ny; ++r){
6518 idx = (size_t)s*nxy+r*nx+c;
6520 rdata[idx] = last_val;
6530 for (
int s = 0; s < nz; ++s) {
6531 for (
int r = 0; r < ny; ++r) {
6532 float last_val =
rdata[s*nxy+r*nx+nx-1];
6533 for (
int c = nx/2; c < nx; ++c){
6534 idx = (size_t)s*nxy+r*nx+c;
6536 rdata[idx] = last_val;
6554#ifdef EMAN2_USING_CUDA
6555 if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) {
6562 if (image->is_complex()) {
6567 int nx = image->get_xsize();
6568 int ny = image->get_ysize();
6569 int nz = image->get_zsize();
6571 if ( ny == 1 && nz == 1 && nx == 1)
return;
6575 float *
rdata = image->get_data();
6577 bool xodd = (nx % 2) == 1;
6578 bool yodd = (ny % 2) == 1;
6579 bool zodd = (nz % 2) == 1;
6581 if ( ny == 1 && nz == 1 ){
6585 float in_x =
rdata[nx/2];
6587 for (
int i = nx-1; i >= nx/2; --i ) {
6594 for (
int i = 0; i < nx/2; ++i ) {
6596 float tmp =
rdata[i];
6601 else if ( nz == 1 ){
6614 for (
int r = 0; r < ny; ++r ) {
6615 float last_val =
rdata[r*nx+nx/2];
6616 for (
int c = nx-1; c >= nx/2; --c ){
6619 rdata[idx] = last_val;
6627 for (
int c = 0; c < nx; ++c ) {
6629 float last_val =
rdata[ny/2*nx + c];
6630 for (
int r = ny-1; r >= ny/2; --r ){
6633 rdata[idx] = last_val;
6655 for (
int s = 0; s < nz; ++s) {
6656 for (
int r = 0; r < ny; ++r) {
6657 float last_val =
rdata[s*nxy+r*nx+nx/2];
6658 for (
int c = nx-1; c >= nx/2; --c){
6659 idx = (size_t)s*nxy+r*nx+c;
6661 rdata[idx] = last_val;
6671 for (
int s = 0; s < nz; ++s) {
6672 for (
int c = 0; c < nx; ++c) {
6673 float last_val =
rdata[s*nxy+ny/2*nx+c];
6674 for (
int r = ny-1; r >= ny/2; --r){
6675 idx = (size_t)s*nxy+r*nx+c;
6677 rdata[idx] = last_val;
6687 for (
int r = 0; r < ny; ++r){
6688 for (
int c = 0; c < nx; ++c) {
6689 float last_val =
rdata[nz/2*nxy+r*nx+c];
6690 for (
int s = nz-1; s >= nz/2; --s) {
6691 idx = (size_t)s*nxy+r*nx+c;
6693 rdata[idx] = last_val;
6708 int nx = image->get_xsize();
6709 int ny = image->get_ysize();
6710 int nz = image->get_zsize();
6720 if ((toupper(((
string)
params[
"sym"])[0])!=
'C' || au<0)&& symavg)
throw InvalidParameterException(
"ERROR: symavg only works with Cn symmetry, and one au must be specified.");
6723 for(
int k = 0; k < nz; ++k ) {
6724 for(
int j = 0; j < ny; ++j ) {
6725 for (
int i = 0; i< nx; ++i) {
6726 float az=atan2(
float(j-ny/2),
float(i-nx/2));
6735 float *d = image->get_data();
6736 for(
int k = 0; k < nz; ++k ) {
6737 for(
int j = 0; j < ny; ++j ) {
6738 for (
int i = 0; i< nx; ++i, ++d) {
6740 Vec3f v(i-ox,j-oy,k-oz);
6746 if ( a == au ) *d = 1;
6764 if (image->get_ndim() != 2) {
6781 float threshold=0.0;
6782 if (
params.
has_key(
"sigma") || !
params.
has_key(
"threshold")) threshold=(float)(image->get_attr(
"mean"))+(
float)(image->get_attr(
"sigma"))*(
float)
params[
"sigma"];
6783 else threshold=
params[
"threshold"];
6790 int nx = image->get_xsize();
6791 int ny = image->get_ysize();
6794 amask->set_size(nx, ny);
6796 float *dat = image->get_data();
6797 float *dat2 = amask->get_data();
6801 if (verbose) printf(
"%f\t%f\t%f\t%d\n",(
float)image->get_attr(
"mean"),(
float)image->get_attr(
"sigma"),threshold,nmaxseed);
6805 EMData *peaks=image->process(
"mask.onlypeaks",
Dict(
"npeaks",0));
6806 vector<Pixel> maxs=peaks->calc_n_highest_locations(nmaxseed);
6809 for (vector<Pixel>::iterator i=maxs.begin(); i<maxs.end(); i++) {
6810 if ((*i).x==0 || (*i).y==0 )
continue;
6811 amask->set_value_at((*i).x,(*i).y,0,1.0);
6812 if (verbose) printf(
"Seed at %d,%d,%d (%1.3f)\n",(*i).x,(*i).y,(*i).z,(*i).value);
6820 for (j = -ny / 2; j < ny / 2; ++j) {
6821 for (i = -nx / 2; i < nx / 2; ++i,++l) {
6822 if ( abs(j) > radius || abs(i) > radius)
continue;
6823 if ( (j * j + i * i) > (radius*radius) || dat[l] < threshold)
continue;
6824 if ( (j * j + i * i) > (radius*radius) )
continue;
6836 if (verbose && iter%10==0) printf(
"%d iterations\n",iter);
6837 for (j=1; j<ny-1; ++j) {
6838 for (i=1; i<nx-1; ++i) {
6840 if (dat2[l])
continue;
6841 if (dat[l]>threshold && (dat2[l-1]||dat2[l+1]||dat2[l+nx]||dat2[l-nx])) {
6851 if (verbose) printf(
"extending mask\n");
6852 if (nshells>0 || nshellsgauss>0) amask->process_inplace(
"mask.addshells.gauss",
Dict(
"val1", nshells,
"val2", nshellsgauss));
6857 memcpy(dat,dat2,image->get_size()*
sizeof(
float));
6859 image->mult(*amask);
6873 memcpy(image->get_data(),tmp->get_data(),(
size_t)image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
6886 if (!image->is_complex()) fft=image->do_fft();
6887 else fft=image->copy();
6897 if (image->has_attr(
"dsbg")) ctf.
dsbg=image->get_attr(
"dsbg");
6898 else ctf.
dsbg=1.0/(ctf.
apix*fft->get_ysize()*4.0);
6907 for (vector<float>::iterator it=ctfc.begin(); it!=ctfc.end(); ++it) *it=fabs(*it);
6919 int fp=fft->get_zsize();
6920 int nx=fft->get_xsize();
6921 int ny=fft->get_ysize();
6924 for (
int k=0; k<fp; k++) {
6926 plnf->set_complex(1);
6928 plnf->set_fftpad(1);
6930 for (
int jy=-ny/2; jy<ny/2; jy++) {
6931 for (
int jx=0; jx<nx/2; jx++) {
6932 if (jx==0 && jy<0)
continue;
6936 float ctfmod=ctfc[r1]*ctfc[r2]*ctfc[r3];
6953 if (purectf) plnf->set_complex_at(jx,jy,ctfmod);
6954 else plnf->set_complex_at(jx,jy,plnf->get_complex_at(jx,jy)*ctfmod);
6961 EMData *pln=plnf->do_ift();
6962 pln->process_inplace(
"xform.phaseorigin.tocenter");
6963 pln->process_inplace(
"normalize");
6964 ret->insert_clip(pln,
IntPoint(-nx/2,k*ny,0));
6973 for (
size_t i=0; i<fft->get_size(); i++) fft->set_value_at_fast(i,i%2==0?1.0f:0.0f);
6979 if (noiseamp!=0 || noiseampwhite!=0) {
6980 EMData *noise =
new EMData(image->get_ysize(),image->get_ysize(),1);
6981 noise->process_inplace(
"testimage.noise.gauss");
6982 noise->do_fft_inplace();
6985 if (noiseampwhite!=0) {
6986 noise->mult((
float)noiseampwhite*15.0f);
6988 noise->mult((
float)1.0/(noiseampwhite*15.0f));
6993 vector <float> pinkbg;
6995 float nyimg=0.5f/ctf.
apix;
6997 for (
int i=0; i<500; i++) pinkbg[i]=noiseamp*(44.0f*exp(-5.0f*nyimg*i/250.0f)+10.0f*exp(-90.0f*nyimg*i/250.0f));
7004 EMData *ret=fft->do_ift();
7017 if (!image->is_complex()) {
7018 LOGERR(
"AddRandomNoise Processor only works for complex image");
7025 vector < float >
y =
params[
"y"];
7027 int interpolation = 1;
7029 interpolation =
params[
"interpolation"];
7037 int nx = image->get_xsize();
7038 int ny = image->get_ysize();
7039 int nz = image->get_zsize();
7042 float *
rdata = image->get_data();
7047 half_nz = nz / 2.0f;
7050 const float sqrt_2 =
sqrt((
float) 2);
7053 for (
int h = 0; h < nz; h++) {
7054 for (
int j = 0; j < ny; j++) {
7055 for (
int i = 0; i < nx; i += 2, k += 2) {
7056 r = (
Util::hypot3(i / 2.0f, j - ny / 2.0f, h - half_nz));
7060 if (interpolation) {
7075 if (interpolation) {
7076 f = (
y[l] * (1 - r) +
y[l + 1] * r);
7083 float a = randnum->
get_frand(0.0f, (
float)(2 * M_PI));
7087 rdata[k] += f * cos(a);
7088 rdata[k + 1] += f * sin(a);
7103 int nx = image->get_xsize();
7104 int ny = image->get_ysize();
7105 int nz = image->get_zsize();
7108 LOGERR(
"Error: mask.addshells.multilevel works only in 2/3-D");
7116 EMData *image2=image->copy();
7118 for (
int i = 0; i < num_shells; i++) {
7119 for (
int y = 1;
y < ny - 1;
y++) {
7120 for (
int x = 1;
x < nx - 1;
x++) {
7121 if (image1->get_value_at(
x,
y)>0)
continue;
7126 if (image1->get_value_at(
x-1,
y)>0) image2->set_value_at_fast(
x,
y,image1->get_value_at(
x-1,
y));
7127 else if (image1->get_value_at(
x+1,
y)>0) image2->set_value_at_fast(
x,
y,image1->get_value_at(
x+1,
y));
7128 else if (image1->get_value_at(
x,
y-1)>0) image2->set_value_at_fast(
x,
y,image1->get_value_at(
x,
y-1));
7129 else if (image1->get_value_at(
x,
y+1)>0) image2->set_value_at_fast(
x,
y,image1->get_value_at(
x,
y+1));
7133 memcpy(image1->get_data(),image2->get_data(),image1->get_size()*
sizeof(
float));
7137 for (
int i = 0; i < num_shells; i++) {
7138 for (
int z = 1; z < nz - 1; z++) {
7139 for (
int y = 1;
y < ny - 1;
y++) {
7140 for (
int x = 1;
x < nx - 1;
x++) {
7141 if (image1->get_value_at(
x,
y,z)>0)
continue;
7146 if (image1->get_value_at(
x-1,
y,z)>0) image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x-1,
y,z));
7147 else if (image1->get_value_at(
x+1,
y,z)>0) image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x+1,
y,z));
7148 else if (image1->get_value_at(
x,
y-1,z)>0) image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y-1,z));
7149 else if (image1->get_value_at(
x,
y+1,z)>0) image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y+1,z));
7150 else if (image1->get_value_at(
x,
y,z-1)>0) image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y,z-1));
7151 else if (image1->get_value_at(
x,
y,z+1)>0) image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y,z+1));
7156 memcpy(image1->get_data(),image2->get_data(),image1->get_size()*
sizeof(
float));
7172 int nx = image->get_xsize();
7173 int ny = image->get_ysize();
7174 int nz = image->get_zsize();
7177 LOGERR(
"Tried to add mask shell to 1d image");
7183 float *d = image->get_data();
7188 for (
int i = 0; i < num_shells; i++) {
7189 for (
int y = 1;
y < ny - 1;
y++) {
7192 for (
int x = 1;
x < nx - 1;
x++) {
7194 if (!d[j] && (d[j - 1] > k || d[j + 1] > k || d[j + nx] > k || d[j - nx] > k)) {
7203 for (
int i = 0; i < num_shells; i++) {
7204 for (
int z = 1; z < nz - 1; z++) {
7205 size_t cur_z = (size_t)z * nx * ny;
7207 for (
int y = 1;
y < ny - 1;
y++) {
7208 size_t cur_y =
y * nx + cur_z;
7210 for (
int x = 1;
x < nx - 1;
x++) {
7211 size_t j =
x + cur_y;
7213 if (!d[j] && (d[j - 1] > k || d[j + 1] > k || d[j + nx] > k ||
7214 d[j - nx] > k || d[j - nxy] > k || d[j + nxy] > k)) {
7225 size_t size = (size_t)nx * ny * nz;
7226 for (
size_t i = 0; i < size; ++i) {
7245 float thr =
params[
"thr"];
7246 string symname=(string)
params[
"sym"];
7249 int nx = image->get_xsize();
7250 int ny = image->get_ysize();
7251 int nz = image->get_zsize();
7253 if (ny == 1 || nz==1) {
7254 LOGERR(
"Error: segment.subunit works only in 3-D");
7261 EMData *image2=image->copy();
7264 image2->process_inplace(
"mask.sharp",
Dict(
"inner_radius",(
int)nz/5));
7265 IntPoint ml=image2->calc_max_location();
7269 vector<Transform> transforms = sym->
get_syms();
7270 for(vector<Transform>::const_iterator trans_it = transforms.begin(); trans_it != transforms.end(); trans_it++) {
7274 image1->set_value_at((
int)(xf[0]+nx/2),(
int)(xf[1]+ny/2),(
int)(xf[2]+nz/2),(
float)i);
7276 memcpy(image2->get_data(),image1->get_data(),image1->get_size()*
sizeof(
float));
7281 float max=(float)image->get_attr(
"maximum");
7285 for (
int ti=0; ti<12; ti++) {
7286 float thr2=max-(ti+1)*gap/12.0;
7287 printf(
"threshold %1.4f\n",thr2);
7291 for (
int z = 1; z < nz - 1; z++) {
7292 for (
int y = 1;
y < ny - 1;
y++) {
7293 for (
int x = 1;
x < nx - 1;
x++) {
7295 if (image1->get_value_at(
x,
y,z)>0 || image->get_value_at(
x,
y,z)<thr2)
continue;
7300 if (image1->get_value_at(
x-1,
y,z)>0) { image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x-1,
y,z)); change=1; }
7301 else if (image1->get_value_at(
x+1,
y,z)>0) { image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x+1,
y,z)); change=1; }
7302 else if (image1->get_value_at(
x,
y-1,z)>0) { image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y-1,z)); change=1; }
7303 else if (image1->get_value_at(
x,
y+1,z)>0) { image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y+1,z)); change=1; }
7304 else if (image1->get_value_at(
x,
y,z-1)>0) { image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y,z-1)); change=1; }
7305 else if (image1->get_value_at(
x,
y,z+1)>0) { image2->set_value_at_fast(
x,
y,z,image1->get_value_at(
x,
y,z+1)); change=1; }
7310 memcpy(image1->get_data(),image2->get_data(),image1->get_size()*
sizeof(
float));
7322 memcpy(image->get_data(),image1->get_data(),image1->get_size()*
sizeof(
float));
7338 if ((
float)image->get_attr(
"sigma")==0.0f)
return;
7339 int nx = image->get_xsize();
7340 int ny = image->get_ysize();
7341 int nz = image->get_zsize();
7344 float gmw=(nx/16)>5?nx/16:5;
7345 EMData *image2=image->process(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",nx<50?nx/10:5));
7346 image2->process_inplace(
"normalize.circlemean",
Dict(
"radius",ny/2-4));
7347 image2->process_inplace(
"mask.gaussian",
Dict(
"inner_radius",nx/2-gmw,
"outer_radius",gmw/1.3));
7348 image2->process_inplace(
"math.squared");
7349 image2->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.05));
7350 image2->process_inplace(
"normalize.circlemean",
Dict(
"radius",ny/2-6));
7353 float hmin=(float)image2->get_attr(
"mean");
7354 float hmax=(float)image2->get_attr(
"mean")+(float)image2->get_attr(
"sigma")*4.0;
7355 vector <float> hist = image2->
calc_hist( 100,hmin,hmax);
7358 for (i=99; i>=0; i--) {
7360 if (tot>nx*ny*nz/10)
break;
7362 float thr=(i*hmax+(99-i)*hmin)/99.0;
7366 image2->process_inplace(
"threshold.belowtozero",
Dict(
"minval",thr));
7371 if (nz==1) image3=image2->process(
"mask.auto2d",
Dict(
"radius",nx/10,
"threshold",thr*0.9,
"nmaxseed",5));
7372 else image3=image2->process(
"mask.auto3d",
Dict(
"radius",nx/10,
"threshold",thr*0.9,
"nmaxseed",5));
7375 if (nz==1 && (
float)image3->get_attr(
"sigma")==0) {
7377 image3=image2->process(
"math.linearpyramid");
7380 image3->process_inplace(
"mask.auto2d",
Dict(
"threshold",0.5,
"nmaxseed",5));
7384 image3->process_inplace(
"threshold.binary",
Dict(
"value",thr));
7386 if ((
float)image3->get_attr(
"sigma")==0)
delete image3;
7393 FloatPoint com = image2->calc_center_of_mass(0.5);
7397 int dx = -(floor(com[0] + 0.5f) - nx / 2);
7398 int dy = -(floor(com[1] + 0.5f) - ny / 2);
7401 dz = -(floor(com[2] + 0.5f) - nz / 2);
7403 if (abs(dx)>=nx-1 || abs(dy)>=ny-1 || abs(dz)>=nz) {
7404 printf(
"ERROR, center of mass outside image\n");
7410 t.
set_trans((
float)dx,(
float)dy,(
float)dz);
7413 image->set_attr(
"xform.align3d",&t);
7415 image->set_attr(
"xform.align2d",&t);
7435 if ((
float)image->get_attr(
"sigma")==0.0f)
return;
7436 if (threshold>(
float)image->get_attr(
"maximum")) {
7437 printf(
"Warning, centering threshold %1.2f, but image max %1.2f. Adjusting.",threshold,(
float)image->get_attr(
"maximum"));
7438 threshold=(float)image->get_attr(
"mean")+(float)image->get_attr(
"sigma");
7442 if (powercenter) { tmp=image; image=tmp->process(
"math.squared"); }
7443 FloatPoint com = image->calc_center_of_mass(threshold);
7444 if (powercenter) {
delete image; image=tmp; }
7446 int nx = image->get_xsize();
7447 int ny = image->get_ysize();
7448 int nz = image->get_zsize();
7450 if (int_shift_only) {
7451 int dx = -(floor(com[0] + 0.5f) - nx / 2);
7452 int dy = -(floor(com[1] + 0.5f) - ny / 2);
7455 dz = -(floor(com[2] + 0.5f) - nz / 2);
7457 if (abs(dx)>=nx-1 || abs(dy)>=ny-1 || abs(dz)>=nz) {
7458 printf(
"ERROR, center of mass outside image\n");
7464 t.
set_trans((
float)dx,(
float)dy,(
float)dz);
7467 image->set_attr(
"xform.align3d",&t);
7469 image->set_attr(
"xform.align2d",&t);
7474 float dx = -(com[0] - nx / 2);
7475 float dy = -(com[1] - ny / 2);
7478 dz = -(com[2] - nz / 2);
7480 if (fabs(dx)>=nx-1 || fabs(dy)>=ny-2 || fabs(dz)>=nz) {
7481 printf(
"ERROR, center of mass outside image\n");
7490 image->set_attr(
"xform.align3d",&t);
7492 image->set_attr(
"xform.align2d",&t);
7507 vector<float> pcog = image->phase_cog();
7509 int dims = image->get_ndim();
7511 if (int_shift_only) {
7512 int dx=-int(pcog[0]+0.5f),dy=0,dz=0;
7513 if ( dims >= 2 ) dy = -int(pcog[1]+0.5);
7514 if ( dims == 3 ) dz = -int(pcog[2]+0.5);
7517 t.
set_trans((
float)dx,(
float)dy,(
float)dz);
7518 if (dims == 3) image->set_attr(
"xform.align3d",&t);
7519 else if (dims == 2) image->set_attr(
"xform.align2d",&t);
7523 float dx=-pcog[0],dy=0.0,dz=0.0;
7524 if ( dims >= 2 ) dy = -pcog[1];
7525 if ( dims == 3 ) dz = -pcog[2];
7530 if (dims == 3) image->set_attr(
"xform.align3d",&t);
7531 else if (dims == 2) image->set_attr(
"xform.align2d",&t);
7543 params1[
"intonly"] = 1;
7544 params1[
"maxshift"] = image->get_xsize() / 4;
7545 EMData* aligned = image->align(
"translational", 0, params1);
7546 if ( image->get_ndim() == 3 ) {
7547 Transform* t = aligned->get_attr(
"xform.align3d");
7549 image->set_attr(
"xform.align3d",t);
7554 Transform* t = aligned->get_attr(
"xform.align2d");
7556 image->set_attr(
"xform.align2d",t);
7567 size_t n = (size_t)image->get_xsize()*image->get_ysize()*image->get_zsize();
7568 memcpy(image->get_data(),tmp->get_data(),n*
sizeof(
float));
7575 const char *fsp =
params[
"fscfile"];
7582 float nyquist=1.0/(2.0f*(float)image->get_attr(
"apix_x"));
7588 for (
int i=0; i<N; i++) {
7589 float s=i*nyquist/N;
7590 float f=fsc.
get_y(i);
7592 if (s>=maxfreq && lf<f) f=lf*.9;
7593 if (f<0 && i>2) localav=1;
7594 if (localav==1 && i>N-3) f=lf;
7596 else if (localav==2) f=.00001;
7598 if (f>=1.0) f=.9999;
7599 if (f<0) { localav=2; f=.00001; }
7601 snr=snrmult*f/(1.0-f);
7602 float wiener=snr*snr/(snr*snr+1);
7603 if (wiener<.001) wiener=.001;
7605 fsc.
set_y(i,wiener);
7610 FILE *out=fopen(
"wiener.txt",
"w");
7611 vector<float> wienerary(image->get_ysize());
7612 for (
int i=0; i<image->get_ysize(); i++) {
7613 wienerary[i]=fsc.
get_yatx(i*nyquist/image->get_ysize());
7614 fprintf(out,
"%f\t%f\n",sscale*i*nyquist/image->get_ysize(),wienerary[i]);
7618 EMData *fft=image->do_fft();
7621 EMData *ret=fft->do_ift();
7633 int wiener =
params[
"wiener"];
7634 const char *snrfile =
params[
"snrfile"];
7639 LOGERR(
"couldn't read structure factor file!");
7644 for (
size_t i = 0; i < sf.
get_size(); i++) {
7645 if (sf.
get_y(i) <= 0) {
7654 Ctf *image_ctf = image->get_ctf();
7656 vector < float >ctf;
7664 if(image_ctf) {
delete image_ctf; image_ctf=0;}
7666 image->process_inplace(
"normalize.circlemean");
7668 int nx = image->get_xsize();
7669 int ny = image->get_ysize();
7671 Region clip_r(-nx / 2, -ny / 2, nx * 2, ny * 2);
7673 EMData *d2 = d3->do_fft();
7690 EMData *d1 = d2->do_ift();
7691 int d1_nx = d1->get_xsize();
7692 int d1_ny = d1->get_ysize();
7693 Region d1_r(d1_nx / 4, d1_ny / 4, d1_nx / 2, d1_ny / 2);
7725 int ny = image->get_ysize();
7727 if (image->has_attr(
"ctf") && useheader){
7744 int np=(int)ceil(ny*1.73)+1;
7750 for (i=1; i<np/2-1; i++) {
7751 if (filter[i+1]<filter[i]) {
7752 filter[i]=1.0/filter[i];
7755 filter[i]=1.0/filter[i];
7759 if (phaseflip) filter[i]=filter[gi]*(filter[i]<0?-1.0f:1.0f);
7760 else filter[i]=filter[gi];
7765 for (
int i=0; i<(int)hppix*3.0; i++) filter[i]*=tanh((
float)i/hppix);
7769 image->process_inplace(
"filter.radialtable",
Dict(
"table",filter));
7779 const char *filename =
params[
"filename"];
7780 float apix =
params[
"apix"];
7782 FILE *in = fopen(filename,
"rb");
7784 LOGERR(
"FileFourierProcessor: cannot open file '%s'", filename);
7790 while (fscanf(in,
" %f %f", &f, &f) == 2) {
7795 vector < float >xd(n);
7796 vector < float >yd(n);
7798 float sf = apix * image->get_xsize();
7800 for (
int i = 0; fscanf(in,
" %f %f", &xd[i], &yd[i]) == 2; i++) {
7804 if (xd[2] - xd[1] != xd[1] - xd[0]) {
7805 LOGWARN(
"Warning, x spacing appears nonuniform %g!=%g\n",
7806 xd[2] - xd[1], xd[1] - xd[0]);
7809 EMData *d2 = image->do_fft();
7817 image = d2->do_ift();
7829 int nx=image->get_xsize();
7830 int ny=image->get_ysize();
7836 int mincol = *min_element(cols.begin(),cols.end());
7837 int maxcol = *max_element(cols.begin(),cols.end());
7839 int minrow = *min_element(rows.begin(),rows.end());
7840 int maxrow = *max_element(rows.begin(),rows.end());
7849 for (
int x=mincol-1;
x<=maxcol+1;
x++) {
7851 for (
int i=0; i<=cols.size(); i++)
if (
x==cols[i]) inflag =
true;
7852 if (inflag ==
true)
continue;
7855 for (
int i=0; i<=cols.size(); i++)
if ((
x-1)==cols[i]) inflag =
true;
7856 if (inflag ==
true){
7859 for (
int c=start; c<ngl; c++) {
7862 for (
int y=0;
y<ny;
y++) {
7863 float val = ((image->get_value_at(ogl,
y)*(ngl-ogl-pos)+image->get_value_at(ngl,
y)*pos)) / (nnorm*(ngl-ogl));
7864 image->set_value_at(c,
y,val);
7874 for (
int y=minrow-1;
y<=maxrow+1;
y++) {
7876 for (
int i=0; i<=rows.size(); i++)
if (
y==rows[i]) inflag =
true;
7877 if (inflag ==
true)
continue;
7880 for (
int i=0; i<=rows.size(); i++)
if ((
y-1)==rows[i]) inflag =
true;
7881 if (inflag ==
true){
7883 for (
int r=ogl+1; r<ngl; r++) {
7886 for (
int x=0;
x<nx;
x++) {
7887 float val = ((image->get_value_at(
x,ogl)*(ngl-ogl-pos)+image->get_value_at(
x,ngl)*pos)) / (nnorm*(ngl-ogl));
7888 image->set_value_at(
x,r,val);
7908 int nx=image->get_attr(
"nx");
7909 int ny=image->get_attr(
"ny");
7916 for (
int x=0;
x<nx;
x++) {
7919 for (
int y=0;
y<(ylen<ny?ylen:ny);
y++) { sum+=image->get_value_at(
x,
y); sumn+=1.0; }
7921 for (
int y=0;
y<ny;
y++) {
7922 if (
y+ylen<ny) { sum+=image->get_value_at(
x,
y+ylen); sumn+=1.0; }
7923 if (
y-ylen-1>=0) { sum-=image->get_value_at(
x,
y-ylen-1); sumn-=1.0; }
7924 tmp->set_value_at_fast(
x,
y,sum/sumn);
7927 tmp->write_image(
"tmp.hdf",0);
7933 for (
int y=0;
y<ny;
y++) {
7936 for (
int x=0;
x<(xlen<nx?xlen:nx);
x++) { sum+=image->get_value_at(
x,
y); sumn+=1.0; }
7938 for (
int x=0;
x<nx;
x++) {
7939 if (
x+xlen<nx) { sum+=image->get_value_at(
x+xlen,
y); sumn+=1.0; }
7940 if (
x-xlen-1>=0) { sum-=image->get_value_at(
x-xlen-1,
y); sumn-=1.0; }
7941 tmp->set_value_at_fast(
x,
y,sum/sumn);
7944 tmp->write_image(
"tmp.hdf",1);
7958 float apix =
params[
"apix"];
7959 float threshold =
params[
"threshold"];
7960 float radius =
params[
"radius"];
7963 int ny = image->get_ysize();
7964 radius = ny * apix / radius;
7968 EMData *blur = image->copy();
7969 EMData *maskblur = image->copy();
7971 maskblur->process_inplace(
"threshold.binary",
Dict(
"value", threshold));
7972 maskblur->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_pixels", radius));
7974 maskblur->process_inplace(
"threshold.belowtozero",
Dict(
"minval", 0.001f));
7978 blur->process_inplace(
"threshold.belowtozero",
Dict(
"minval", threshold));
7979 blur->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_pixels", radius));
7982 maskblur->div(*blur);
7983 image->mult(*maskblur);
8006 float thresh =
params[
"thresh"];
8007 int output_symlabel =
params[
"output_symlabel"];
8010 const vector<string> sym_list =
params[
"sym"];
8011 int sym_num = sym_list.
size();
8012 vector< vector< Transform > > transforms(sym_num);
8013 vector< float* > symvals(sym_num);
8014 for (
int i =0; i < sym_num; i++) {
8016 transforms[i] = sym_transform;
8017 symvals[i] =
new float[sym_transform.size()];
8020 EMData *orig = image->copy();
8024 int nx= image->get_xsize();
8025 int ny= image->get_ysize();
8026 int nz= image->get_zsize();
8028 float * data = image->get_data();
8029 float * sdata = orig->get_data();
8032 float * ldata = symlabel->get_data();
8033 if (output_symlabel) {
8034 symlabel = image->copy();
8035 symlabel->to_zero();
8036 ldata = symlabel->get_data();
8039 for (
int k = 0; k < nz; k++) {
8040 for (
int j = 0; j < ny; j++) {
8041 for(
int i = 0; i < nx; i++) {
8042 size_t index = (size_t)k * nx * ny + j * nx + i;
8043 float val = sdata[ index ];
8044 float bestmean = val, bestsymlevel = FLT_MAX;
8046 for(
int sym = 0; sym< sym_num; sym++) {
8047 int cur_sym_num = transforms[sym].size();
8048 float *symval = symvals[sym];
8050 for(
int s = 0; s < cur_sym_num; s++){
8052 float x2 = (float)(r[0][0] * (i-nx/2) + r[0][1] * (j-ny/2) + r[0][2] * (k-nz/2) + nx / 2);
8053 float y2 = (float)(r[1][0] * (i-nx/2) + r[1][1] * (j-ny/2) + r[1][2] * (k-nz/2) + ny / 2);
8054 float z2 = (float)(r[2][0] * (i-nx/2) + r[2][1] * (j-ny/2) + r[2][2] * (k-nz/2) + nz / 2);
8056 if (x2 >= 0 && y2 >= 0 && z2 >= 0 && x2 < (nx - 1) && y2 < (ny - 1)
8066 size_t ii =
x +
y * nx + z * (size_t)xy;
8070 sdata[ii + nx + 1], sdata[ii + nx * ny],
8071 sdata[ii + xy + 1], sdata[ii + xy + nx],
8072 sdata[ii + xy + nx + 1], t, u, v);
8078 float tmean=0, tsigma=0;
8079 for(
int s = 0; s < cur_sym_num; s++) {
8081 tsigma += symval[s] * symval[s];
8083 tmean /= cur_sym_num;
8084 tsigma = tsigma/cur_sym_num - tmean*tmean;
8085 if (tsigma < bestsymlevel ) {
8086 bestsymlevel = tsigma;
8091 if ( bestsymlevel > thresh) {
8092 if (output_symlabel) ldata[index] = (float)bestsym;
8093 data[index] = bestmean;
8096 if (output_symlabel) ldata[index] = -1;
8107 for (
int i =0; i < sym_num; i++) {
8127 const char *filename =
params[
"filename"];
8128 mask=
new EMData(filename,0);
8131 LOGERR(
"IndexMaskFileProcessor: Mask size different than image");
8135 else mask=mask->copy();
8139 mask->process_inplace(
"threshold.binaryrange",
Dict(
"low", (
float)(maskset-0.5),
"high", (
float)(maskset+0.5)));
8231 float apixto = to->get_attr(
"apix_x");
8235 if (to->get_ysize() != image->get_ysize())
throw ImageDimensionException(
"Fatal Error: filter.matchto - image sizes must match");
8243 if (to->is_complex()) tofft=to;
8244 else tofft=to->do_fft();
8247 if (image->get_zsize()>1) cornerscale=
sqrt(3.0);
8248 else cornerscale=
sqrt(2.0);
8250 int ny=image->get_ysize();
8251 int ny2=(int)floor(image->get_ysize()*cornerscale/2);
8252 vector <float>norm(ny2+1);
8253 for (
int i=0; i<ny2; i++) norm[i]=rad[i]=0;
8255 for (
int y=-ny;
y<ny;
y++) {
8256 for (
int x=0;
x<ny;
x++) {
8258 if (r>ny2)
continue;
8259 std::complex<float> v1=image->get_complex_at(
x,
y);
8260 std::complex<float> v2=tofft->get_complex_at(
x,
y);
8261 rad[r]+=(double)(v1.real()*v2.real()+v1.imag()*v2.imag());
8262 norm[r]+=(double)(v2.real()*v2.real()+v2.imag()*v2.imag());
8266 for (
int i=0; i<ny2; i++) {
8267 rad[i]=(rad[i]/norm[i]<0)?0.0:rad[i]/norm[i];
8273 for (
int i=0; i<ny2; i++) {
8274 if (rad[i]<radmean/100.0) rad[i]=radmean/100.0;
8278 if (!to->is_complex())
delete tofft;
8283 if (to->is_complex()) {
8285 for (
size_t i=0; i<rd.size(); ++i) {
8286 if (rad[i]>0) rad[i]=
sqrt(rd[i]/rad[i]);
8290 EMData *tmp=to->do_fft();
8292 for (
size_t i=0; i<rd.size(); ++i) {
8293 if (rad[i]>0) rad[i]=
sqrt(rd[i]/rad[i]);
8301 for (
int i=0; i<rad.size(); i++) radmean+=rad[i];
8302 radmean/=rad.size();
8303 for (
int i=0; i<rad.size(); i++) {
8304 if (rad[i]<radmean/100.0) rad[i]=radmean/100.0;
8314 if (!image->is_complex()) { tmp=image; image=tmp->do_fft(); }
8322 image->set_attr(
"apix_x", (
float)
params[
"apix"]);
8323 image->set_attr(
"apix_y", (
float)
params[
"apix"]);
8324 image->set_attr(
"apix_z", (
float)
params[
"apix"]);
8325 if (image->has_attr(
"ctf")) {
8326 Ctf *ctf=image->get_attr(
"ctf");
8328 image->set_attr(
"ctf",ctf);
8333 float apix=image->get_attr(
"apix_x");
8334 int nx=image->get_xsize();
8335 int ny=image->get_ysize();
8336 int nz=image->get_zsize();
8339 for (
int j=-ny/2; j<ny/2; j++) {
8340 for (
int i=0; i<nx/2; i++) {
8341 float r=
Util::hypot2(i/(
float)(nx-2),j/(
float)ny)/apix;
8343 std::complex<float> v=image->get_complex_at(i,j);
8344 if (v!=0.0f) v*=a/abs(v);
8345 else v=std::complex<float>(a,0);
8346 image->set_complex_at(i,j,v);
8351 for (
int k=-nz/2; k<nz/2; k++) {
8352 for (
int j=-ny/2; j<ny/2; j++) {
8353 for (
int i=0; i<nx/2; i++) {
8354 float r=
Util::hypot3(i/(
float)(nx-2),j/(
float)ny,k/(
float)nz)/apix;
8356 std::complex<float> v=image->get_complex_at(i,j,k);
8357 if (v!=0.0f) v*=a/abs(v);
8358 else v=std::complex<float>(a,0);
8359 image->set_complex_at(i,j,k,v);
8366 EMData *tmp2=image->do_ift();
8367 memcpy(tmp->get_data(),tmp2->get_data(),tmp2->get_size()*
sizeof(
float));
8385 else sf =
params[
"strucfac"];
8387 image->set_attr(
"apix_x", (
float)
params[
"apix"]);
8388 image->set_attr(
"apix_y", (
float)
params[
"apix"]);
8389 image->set_attr(
"apix_z", (
float)
params[
"apix"]);
8390 if (image->has_attr(
"ctf")) {
8391 Ctf *ctf=image->get_attr(
"ctf");
8393 image->set_attr(
"ctf",ctf);
8399 float apix=image->get_attr(
"apix_x");
8400 int ny=image->get_ysize();
8401 int n = radial_mask.size();
8405 if ((nmax)<3)
throw InvalidParameterException(
"Insufficient structure factor data for SetSFProcessor to be meaningful");
8409 for (i=1; i<nmax; i++) {
8414 if (radial_mask[i]>0) {
8415 radial_mask[i]=
sqrt((ny*ny*ny)*scale*sf->
get_yatx(i/(apix*ny))/radial_mask[i]);
8417 else if (i>0) radial_mask[i]=radial_mask[i-1];
8424 radial_mask[i]=radial_mask[nmax-1];
8438 float mask =
params[
"mask"];
8440 int nx = image->get_xsize();
8441 int ny = image->get_ysize();
8442 int nz = image->get_zsize();
8444 float *dat = image->get_data();
8448 for (
int k = 0; k < nz; ++k) {
8449 for (
int j = 0; j < ny; ++j) {
8450 for (
int i = 0; i < nx; ++i, ++dat) {
8454 if (r > mask - 1.5f && r < mask - 0.5f) {
8462 float smask = (float) (sma / smn);
8465 dat = image->get_data();
8466 for (
int k = 0; k < nz; ++k) {
8467 for (
int j = 0; j < ny; ++j) {
8468 for (
int i = 0; i < nx; ++i, ++dat) {
8472 if (r > mask - .5) {
8494 float sig = image->get_attr(
"sigma");
8495 float mean = image->get_attr(
"mean");
8500 EMData *mask=image->copy();
8501 mask->process_inplace(
"threshold.binary",
Dict(
"value",thr1));
8503 EMData *mask2=image->copy();
8504 mask2->process_inplace(
"threshold.binary",
Dict(
"value",thr2));
8505 float maskmean=mask->get_attr(
"mean");
8506 for (
int i=0; i<1000; i++){
8507 mask->process_inplace(
"mask.addshells",
Dict(
"nshells",2));
8509 if (
float(mask->get_attr(
"mean"))==maskmean)
8511 maskmean=mask->get_attr(
"mean");
8517 int nshells =
params[
"nshells"];
8518 int nshellsgauss =
params[
"nshellsgauss"];
8520 mask->process_inplace(
"mask.addshells.gauss",
Dict(
"val1", (
int)(nshells+nshellsgauss/2),
"val2",0));
8522 mask->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs", (
float)(1.0f/(
float)nshellsgauss)));
8524 mask->process_inplace(
"threshold.belowtozero",
Dict(
"minval",(
float)0.002));
8529 float *dat = image->get_data();
8530 float *dat2 = mask->get_data();
8531 memcpy(dat,dat2,image->get_size()*
sizeof(
float));
8550 int nx =
image->get_xsize();
8551 int ny =
image->get_ysize();
8552 int nz =
image->get_zsize();
8559 mask->set_size(nx, ny, nz);
8562 for (
int zz = 0; zz < nz; zz++) {
8563 for (
int yy = 0; yy < ny; yy++) {
8564 for (
int xx = 0; xx < nx; xx++) {
8565 if (
image->get_value_at(xx,yy,zz)>threshold &&
mask->get_value_at(xx,yy,zz)==1.0) {
8567 pvec.push_back(
Vec3i(xx,yy,zz));
8568 for (uint i=0; i<pvec.size(); i++) {
8570 if (
mask->sget_value_at(pvec[i])==0.0f) {
8571 pvec.erase(pvec.begin()+i);
8577 mask->set_value_at(pvec[i],0.0f);
8583 if (
image->sget_value_at(
x-1,
y,z)>threshold &&
mask->get_value_at(
x-1,
y,z)==1.0) pvec.push_back(
Vec3i(
x-1,
y,z));
8584 if (
image->sget_value_at(
x+1,
y,z)>threshold &&
mask->get_value_at(
x+1,
y,z)==1.0) pvec.push_back(
Vec3i(
x+1,
y,z));
8585 if (
image->sget_value_at(
x,
y-1,z)>threshold &&
mask->get_value_at(
x,
y-1,z)==1.0) pvec.push_back(
Vec3i(
x,
y-1,z));
8586 if (
image->sget_value_at(
x,
y+1,z)>threshold &&
mask->get_value_at(
x,
y+1,z)==1.0) pvec.push_back(
Vec3i(
x,
y+1,z));
8587 if (
image->sget_value_at(
x,
y,z-1)>threshold &&
mask->get_value_at(
x,
y,z-1)==1.0) pvec.push_back(
Vec3i(
x,
y,z-1));
8588 if (
image->sget_value_at(
x,
y,z+1)>threshold &&
mask->get_value_at(
x,
y,z+1)==1.0) pvec.push_back(
Vec3i(
x,
y,z+1));
8593 if (pvec.size()>voxels) {
8594 if (verbose) printf(
"%d\t%d\t%d\tvoxels: %d\n",xx,yy,zz,(
int)pvec.size());
8595 for (uint i=0; i<pvec.size(); i++)
mask->set_value_at(pvec[i],2.0);
8602 mask->process_inplace(
"threshold.binary",
Dict(
"value",0.5));
8607 mask->process_inplace(
"mask.addshells",
Dict(
"nshells",2));
8608 mask->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.25f));
8628 if (image->get_ndim() != 3) {
8644 radius =
params[
"radius"];
8648 nmaxseed =
params[
"nmaxseed"];
8651 float threshold=0.0;
8652 if (
params.
has_key(
"sigma")) threshold=(float)(image->get_attr(
"mean"))+(
float)(image->get_attr(
"sigma"))*(
float)
params[
"sigma"];
8653 else threshold=
params[
"threshold"];
8655 int nshells =
params[
"nshells"];
8656 int nshellsgauss =
params[
"nshellsgauss"];
8659 int nx = image->get_xsize();
8660 int ny = image->get_ysize();
8661 int nz = image->get_zsize();
8665 amask->set_size(nx, ny, nz);
8667 float *dat = image->get_data();
8668 float *dat2 = amask->get_data();
8674 vector<Pixel> maxs=image->calc_n_highest_locations(nmaxseed);
8676 for (vector<Pixel>::iterator i=maxs.begin(); i<maxs.end(); i++) {
8677 amask->set_value_at((*i).x,(*i).y,(*i).z,1.0);
8678 if (verbose) printf(
"Seed at %d,%d,%d (%1.3f)\n",(*i).x,(*i).y,(*i).z,(*i).value);
8685 for (k = -nz / 2; k < nz / 2; ++k) {
8686 for (j = -ny / 2; j < ny / 2; ++j) {
8687 for (i = -nx / 2; i < nx / 2; ++i,++l) {
8688 if (abs(k) > radius || abs(j) > radius || abs(i) > radius)
continue;
8689 if ( (k * k + j * j + i * i) > (radius*radius) || dat[l] < threshold)
continue;
8703 if (verbose && iter%10==0) printf(
"%d iterations\n",iter);
8704 for (k=1; k<nz-1; ++k) {
8705 for (j=1; j<ny-1; ++j) {
8706 for (i=1; i<nx-1; ++i) {
8708 if (dat2[l])
continue;
8709 if (dat[l]>threshold && (dat2[l-1]||dat2[l+1]||dat2[l+nx]||dat2[l-nx]||dat2[l-nxy]||dat2[l+nxy])) {
8720 if (verbose) printf(
"expanding mask\n");
8721 amask->process_inplace(
"mask.addshells.gauss",
Dict(
"val1", (
int)(nshells+nshellsgauss/2),
"val2",0));
8722 if (verbose) printf(
"filtering mask\n");
8723 if (nshellsgauss>0) amask->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs", (
float)(1.0f/(
float)nshellsgauss)));
8724 amask->process_inplace(
"threshold.belowtozero",
Dict(
"minval",(
float)0.002));
8729 dat = image->get_data();
8730 dat2 = amask->get_data();
8731 memcpy(dat,dat2,image->get_size()*
sizeof(
float));
8733 image->mult(*amask);
8752 float val1 =
params[
"val1"];
8753 float val2 =
params[
"val2"];
8755 int nx = image->get_xsize();
8756 int ny = image->get_ysize();
8757 int nz = image->get_zsize();
8765 float *d = image->get_data();
8766 float *d2 = image2->get_data();
8768 const int nxy = nx * ny;
8769 size_t size = (size_t)nx * ny * nz;
8773 for (
int l = 1; l <= (int) val1+val2; ++l) {
8774 for (
size_t i=0; i<size; i++) d2[i]=d[i];
8775 for (
int k = 1; k < nz - 1; ++k) {
8776 for (
int j = 1; j < ny - 1; ++j) {
8777 for (
int i = 1; i < nx - 1; ++i) {
8778 size_t t = i + j*nx+(size_t)k*nx*ny;
8780 if (d2[t - 1] || d2[t + 1] || d2[t + nx] || d2[t - nx] || d2[t + nxy] || d2[t - nxy]) d[t] = (float) l + 1;
8787 for (
int l = 1; l <= (int) val1+val2; ++l) {
8788 for (
size_t i=0; i<size; i++) d2[i]=d[i];
8789 for (
int j = 1; j < ny - 1; ++j) {
8790 for (
int i = 1; i < nx - 1; ++i) {
8791 size_t t = i + j * nx;
8793 if (d2[t - 1] || d2[t + 1] || d2[t + nx] || d2[t - nx]) d[t] = (float) l + 1;
8800 for (
int i=0; i<val1+2; i++) vec.push_back(1.0);
8801 for (
int i=0; i<val2; i++) {
8802 vec.push_back(exp(-pow(2.0f*i/(val2),2.0f)));
8805 for (
size_t i = 0; i < size; ++i)
if (d[i]) d[i]=vec[(int)d[i]];
8813 if ( dir ==
"" || ( dir !=
"x" && dir !=
"y" && dir !=
"z" ) )
8816 int nx = image->get_xsize();
8817 int ny = image->get_ysize();
8818 int nz = image->get_zsize();
8820 if (image->has_attr(
"ptcl_repr")) ret->set_attr(
"ptcl_repr",image->get_attr(
"ptcl_repr"));
8821 if (image->has_attr(
"xform_align2d")) ret->set_attr(
"xform_align2d",image->get_attr(
"xform_align2d"));
8822 if (image->has_attr(
"xform_align3d")) ret->set_attr(
"xform_align3d",image->get_attr(
"xform_align3d"));
8823 ret->set_attr(
"apix_y",image->get_attr(
"apix_y"));
8824 ret->set_attr(
"apix_z",image->get_attr(
"apix_z"));
8829 ret->set_size(ny,1,1);
8830 ret->set_attr(
"apix_x",image->get_attr(
"apix_y"));
8831 for (
int y=0;
y<ny;
y++) {
8833 for (
int x=0;
x<nx;
x++) sm+=image->get_value_at(
x,
y);
8834 ret->set_value_at(
y,0,0,sm/nx);
8838 else if (dir==
"y") {
8839 ret->set_size(nx,1,1);
8840 ret->set_attr(
"apix_x",image->get_attr(
"apix_x"));
8841 for (
int x=0;
x<nx;
x++) {
8843 for (
int y=0;
y<ny;
y++) sm+=image->get_value_at(
x,
y);
8844 ret->set_value_at(
x,0,0,sm/ny);
8856 ret->set_size(nz,ny);
8857 ret->set_attr(
"apix_x",image->get_attr(
"apix_z"));
8858 ret->set_attr(
"apix_y",image->get_attr(
"apix_y"));
8865 if (a0>=nx) a0=nx-1;
8866 if (a1>=nx) a1=nx-1;
8868 for (
int y=0;
y<ny;
y++) {
8869 for (
int z=0; z<nz; z++) {
8871 for (
int x=a0;
x<=a1;
x++) sum+=image->get_value_at(
x,
y,z);
8872 ret->set_value_at(z,
y,(
float)sum);
8876 else if ( dir ==
"y" ) {
8877 ret->set_size(nx,nz);
8878 ret->set_attr(
"apix_x",image->get_attr(
"apix_x"));
8879 ret->set_attr(
"apix_y",image->get_attr(
"apix_z"));
8886 if (a0>=ny) a0=ny-1;
8887 if (a1>=ny) a1=ny-1;
8889 for (
int x=0;
x<nx;
x++) {
8890 for (
int z=0; z<nz; z++) {
8892 for (
int y=a0;
y<=a1;
y++) sum+=image->get_value_at(
x,
y,z);
8893 ret->set_value_at(
x,z,(
float)sum);
8897 else if ( dir ==
"z" ) {
8898 ret->set_size(nx,ny);
8899 ret->set_attr(
"apix_x",image->get_attr(
"apix_x"));
8900 ret->set_attr(
"apix_y",image->get_attr(
"apix_y"));
8907 if (a0>=nz) a0=nz-1;
8908 if (a1>=nz) a1=nz-1;
8910 for (
int y=0;
y<ny;
y++) {
8911 for (
int x=0;
x<nx;
x++) {
8913 for (
int z=a0; z<=a1; z++) sum+=image->get_value_at(
x,
y,z);
8914 ret->set_value_at(
x,
y,(
float)sum);
8930 nx = image->get_xsize();
8931 ny = image->get_ysize();
8932 nz = image->get_zsize();
8937 if (!image->is_complex()) {
8938 int nx = image->get_xsize();
8939 int offset = 2 -
nx%2;
8941 image->set_size(
nx+offset,image->get_ysize(),image->get_zsize());
8942 image->set_complex(
true);
8943 if (1 == offset) image->set_fftodd(
true);
8944 else image->set_fftodd(
false);
8945 image->set_fftpad(
true);
8947 image->set_ri(
true);
8953 int nx = image->get_xsize();
8954 int ny = image->get_ysize();
8955 int nz = image->get_zsize();
8956 int w3 = floor(width*3);
8957 float l0 = pow(center-w3,2.0f);
8958 float l1 = pow(center+w3,2.0f);
8963 for (
int x=0;
x<
nx/2;
x++) {
8964 if (abs(
x-center)>w3)
continue;
8965 image->set_complex_at(
x,0,exp(-pow((
x-center)/width,2.0f)));
8970 for (
int y=-
ny/2;
y<
ny/2;
y++) {
8971 for (
int x=0;
x<
nx/2;
x++) {
8973 if (r<center-w3 || r>center+w3)
continue;
8974 image->set_complex_at(
x,
y,exp(-pow((r-center)/width,2.0f)));
8981 for (
int z=-
nz/2; z<
nz/2; z++) {
8982 for (
int y=-
ny/2;
y<
ny/2;
y++) {
8983 for (
int x=0;
x<
nx/2;
x++) {
8985 if (r<center-w3 || r>center+w3)
continue;
8986 image->set_complex_at(
x,
y,z,exp(-pow((r-center)/width,2.0f)));
8996 if (!image->is_complex()) {
8997 int nx = image->get_xsize();
8998 int offset = 2 -
nx%2;
9000 image->set_size(
nx+offset,image->get_ysize(),image->get_zsize());
9001 image->set_complex(
true);
9002 if (1 == offset) image->set_fftodd(
true);
9003 else image->set_fftodd(
false);
9004 image->set_fftpad(
true);
9010 float * d = image->get_data();
9011 int nx = image->get_xsize();
9012 int ny = image->get_ysize();
9013 int nxy = image->get_ysize()*
nx;
9014 int nzon2 = image->get_zsize()/2;
9015 int nyon2 = image->get_ysize()/2;
9018 for (
int z = 0; z< image->get_zsize(); ++z) {
9019 for (
int y = 0;
y < image->get_ysize(); ++
y) {
9020 for (
int x = 0;
x < image->get_xsize()/2; ++
x) {
9022 ry = (float)nyon2 - (
float)
y;
9023 rz = (float)nzon2 - (
float)z;
9025 amp = exp(-sigma*
length);
9029 size_t idx1 = twox +
y*
nx+(size_t)z*nxy;
9030 size_t idx2 = idx1 + 1;
9039 if (image->get_ndim() == 2) {
9040 bool yodd = image->get_ysize() % 2 == 1;
9042 int yit = image->get_ysize()/2-1;
9047 for (
int y = 0;
y < yit; ++
y) {
9048 int bot_idx = (
y+offset)*
nx;
9049 int top_idx = (
ny-1-
y)*
nx;
9050 float r1 = d[bot_idx];
9051 float i1 = d[bot_idx+1];
9052 float r2 = d[top_idx];
9053 float i2 = d[top_idx+1];
9054 float r = (r1 + r2)/2.0f;
9055 float i = (i1 + i2)/2.0f;
9061 bot_idx = (
y+offset)*
nx+
nx-2;
9081 if (image->get_ndim() != 1) image->process_inplace(
"xform.fourierorigin.tocorner");
9082 image->do_ift_inplace();
9087using std::ostream_iterator;
9095 if (!image->is_complex()) {
9096 image->do_fft_inplace();
9098 EMData* cpy = image->copy();
9101 transform(sf.begin(),sf.end(),sf.begin(),sqrtf);
9106 vector<float> noise =
params[
"noise"];
9107 vector<float> snr =
params[
"snr"];
9112 for(vector<float>::iterator it = noise.begin(); it != noise.end(); ++it){
9113 if ((*it) == 0) *it = 1;
9115 for(vector<float>::iterator it = snr.begin(); it != snr.end(); ++it){
9116 if ((*it) < 0) *it = 0;
9119 transform(snr.begin(),snr.end(),noise.begin(),snr.begin(),std::multiplies<float>());
9120 transform(snr.begin(),snr.end(),snr.begin(),sqrtf);
9124 int i =
static_cast<int>(snr.size());
9126 float * d = image->get_data();
9127 int nx = image->get_xsize();
9129 int nxy = image->get_ysize()*
nx;
9130 int nzon2 = image->get_zsize()/2;
9131 int nyon2 = image->get_ysize()/2;
9132 float rx, ry, rz, amp;
9135 image->process_inplace(
"xform.fourierorigin.tocenter");
9136 for (
int z = 0; z< image->get_zsize(); ++z) {
9137 for (
int y = 0;
y < image->get_ysize(); ++
y) {
9138 for (
int x = 0;
x < image->get_xsize()/2; ++
x) {
9140 ry = (float)nyon2 - (
float)
y;
9141 rz = (float)nzon2 - (
float)z;
9142 length =
static_cast<int>(
sqrt(rx*rx + ry*ry + rz*rz));
9145 size_t idx1 = twox +
y*
nx+(size_t)z*nxy;
9175 if (image->get_ndim() != 1) image->process_inplace(
"xform.fourierorigin.tocorner");
9176 image->do_ift_inplace();
9184 if (!image->is_complex()) {
9185 int nx = image->get_xsize();
9186 int offset = 2 -
nx%2;
9188 image->set_size(
nx+offset,image->get_ysize(),image->get_zsize());
9189 image->set_complex(
true);
9190 if (1 == offset) image->set_fftodd(
true);
9191 else image->set_fftodd(
false);
9192 image->set_fftpad(
true);
9197 vector<float> profile =
params[
"profile"];
9198 transform(profile.begin(),profile.end(),profile.begin(),sqrtf);
9200 int i =
static_cast<int>(profile.size());
9202 float * d = image->get_data();
9203 int nx = image->get_xsize();
9204 int ny = image->get_ysize();
9205 int nxy = image->get_ysize()*
nx;
9206 int nzon2 = image->get_zsize()/2;
9207 int nyon2 = image->get_ysize()/2;
9208 float rx, ry, rz, amp,
phase;
9211 for (
int z = 0; z< image->get_zsize(); ++z) {
9212 for (
int y = 0;
y < image->get_ysize(); ++
y) {
9213 for (
int x = 0;
x < image->get_xsize()/2; ++
x) {
9215 ry = (float)nyon2 - (
float)
y;
9216 rz = (float)nzon2 - (
float)z;
9217 length =
static_cast<int>(
sqrt(rx*rx + ry*ry + rz*rz));
9220 size_t idx1 = twox +
y*
nx+(size_t)z*nxy;
9221 size_t idx2 = idx1 + 1;
9241 if (image->get_ndim() == 2) {
9242 bool yodd = image->get_ysize() % 2 == 1;
9244 int yit = image->get_ysize()/2-1;
9249 for (
int y = 0;
y < yit; ++
y) {
9250 int bot_idx = (
y+offset)*
nx;
9251 int top_idx = (
ny-1-
y)*
nx;
9252 float r1 = d[bot_idx];
9253 float i1 = d[bot_idx+1];
9254 float r2 = d[top_idx];
9255 float i2 = d[top_idx+1];
9256 float r = (r1 + r2)/2.0f;
9257 float i = (i1 + i2)/2.0f;
9263 bot_idx = (
y+offset)*
nx+
nx-2;
9283 if (image->get_ndim() != 1) image->process_inplace(
"xform.fourierorigin.tocorner");
9284 image->do_ift_inplace();
9293 size_t n = (size_t)image->get_xsize()*image->get_ysize()*image->get_zsize();
9295 for(
size_t i = 0; i < n; ++i) {
9296 float x = fmod((
float)i,period);
9299 image->set_value_at_fast(i,
x);
9307 float sigma =
params[
"sigma"];
9308 string axis = (
const char*)
params[
"axis"];
9311 float *dat = image->get_data();
9314 for (
int k = 0; k <
nz; ++k) {
9315 for (
int j = 0; j <
ny; ++j) {
9316 for (
int i = 0; i <
nx; ++i, ++dat) {
9317 x2 = (float)( i -
nx/2 );
9318 y2 = (float)( j -
ny/2 );
9319 z2 = (float)( k -
nz/2 );
9322 r = (float)
sqrt(x2*x2+y2*y2+z2*z2);
9324 else if(axis ==
"x"){
9327 r = ( (float)
sqrt((x2-lc)*(x2-lc)+y2*y2+z2*z2) +
9328 (float)
sqrt((x2-rc)*(x2-rc)+y2*y2+z2*z2) ) /2.0f - c;
9330 else if(axis ==
"y"){
9333 r = ( (float)
sqrt(x2*x2+(y2-lc)*(y2-lc)+z2*z2) +
9334 (float)
sqrt(x2*x2+(y2-rc)*(y2-rc)+z2*z2) ) /2.0f - c;
9336 else if(axis ==
"z"){
9342 r = ( (float)
sqrt(x2*x2+y2*y2+(z2-lc)*(z2-lc)) +
9343 (float)
sqrt(x2*x2+y2*y2+(z2-rc)*(z2-rc)) ) /2.0f - c;
9349 *dat = (float)gsl_ran_gaussian_pdf((
double)r,(double)sigma);
9370 for(
int k=0; k<
nz;++k) {
9371 for(
int j=0; j<
ny; ++j) {
9372 for(
int i=0; i <
nx; ++i) {
9373 image->set_value_at(i,j,k,m*i+b);
9378 else if ( axis ==
"y")
9380 for(
int k=0; k<
nz;++k) {
9381 for(
int j=0; j<
ny; ++j) {
9382 for(
int i=0; i <
nx; ++i) {
9383 image->set_value_at(i,j,k,m*j+b);
9388 else if ( axis ==
"z")
9390 for(
int k=0; k<
nz;++k) {
9391 for(
int j=0; j<
ny; ++j) {
9392 for(
int i=0; i <
nx; ++i) {
9393 image->set_value_at(i,j,k,m*k+b);
9415 int xoffset = (
nx % 2 == 0? 1:0);
9416 int yoffset = (
ny % 2 == 0? 1:0);
9417 int zoffset = (
nz % 2 == 0? 1:0);
9424 if (
nx == 1 &&
ny == 1 &&
nz == 1 )
9428 else if (
ny == 1 &&
nz == 1 )
9431 if ( radius > cx ) radius = cx;
9433 (*image)(cx) = fill;
9434 for (
int i = 1; i <= radius-xoffset; ++i ) (*image)(cx+i) = fill;
9435 for (
int i = 1; i <= radius; ++i ) (*image)(cx-i) = fill;
9443 if ( radius > min ) radius = min;
9445 (*image)(cx,cy) = fill;
9447 for (
int i = 1; i <= radius-xoffset; ++i ) (*image)(cx+i,cy) = fill;
9448 for (
int i = 1; i <= radius-yoffset; ++i )(*image)(cx,cy+i) = fill;
9450 for (
int i = 1; i <= radius; ++i )
9452 (*image)(cx-i,cy) = fill;
9453 (*image)(cx,cy-i) = fill;
9461 if (
nz < min ) min =
nz;
9465 if ( radius > min ) radius = min;
9468 (*image)(cx,cy,cz) = fill;
9469 for (
int i = 1; i <=radius-xoffset; ++i ) (*image)(cx+i,cy,cz) = fill;
9470 for (
int i = 1; i <=radius-yoffset; ++i ) (*image)(cx,cy+i,cz) = fill;
9471 for (
int i = 1; i <=radius-zoffset; ++i ) (*image)(cx,cy,cz+i) = fill;
9472 for (
int i = 1; i <= radius; ++i )
9474 (*image)(cx-i,cy,cz) = fill;
9475 (*image)(cx,cy-i,cz) = fill;
9476 (*image)(cx,cy,cz-i) = fill;
9487 int dim_size = image->get_ndim();
9488 if( 2 != dim_size ) {
9492 int nx = image->get_xsize();
9493 int ny = image->get_ysize();
9496 for (
int i=0; i<100; i++) {
9497 int x=
static_cast<int>(
nx/2+
nx/6.0*sin(i*2.0*3.14159/100.0) );
9498 int y=
ny/4+i*
ny/200;
9499 for (
int xx=
x-
nx/10; xx<
x+
nx/10; xx++) {
9500 for (
int yy=
y-
ny/10; yy<
y+
ny/10; yy++) {
9501 (*image)(xx,yy)+=exp(-pow(
static_cast<float>(hypot(xx-
x,yy-
y))*30.0f/
nx,2.0f))*(sin(
static_cast<float>((xx-
x)*(yy-
y)))+.5f);
9513 float x_sigma =
params[
"x_sigma"];
9514 float y_sigma =
params[
"y_sigma"];
9515 float z_sigma =
params[
"z_sigma"];
9517 float x_center =
params[
"x_center"];
9518 float y_center =
params[
"y_center"];
9519 float z_center =
params[
"z_center"];
9521 int nx = image->get_xsize();
9522 int ny = image->get_ysize();
9523 int nz = image->get_zsize();
9525 float x_twosig2 = 2*x_sigma*x_sigma;
9526 float y_twosig2 = 2*y_sigma*y_sigma;
9527 float z_twosig2 = 2*z_sigma*z_sigma;
9529 float sr2pi =
sqrt( 2.0f*(
float)pi );
9530 float norm = 1.0f/ ( x_sigma*sr2pi );
9532 norm *= 1.0f/ ( y_sigma*sr2pi );
9533 if (
nz > 1) norm *= 1.0f/ ( z_sigma*sr2pi );
9536 float z,
y,
x, sum, val;
9537 for (
int iz=0; iz <
nz; ++iz) {
9538 z =
static_cast<float>(iz) - z_center;
9539 for (
int iy=0; iy <
ny; ++iy) {
9540 y =
static_cast<float>(iy) - y_center;
9541 for (
int ix=0; ix <
nx; ++ix) {
9542 x =
static_cast<float>(ix) - x_center;
9543 sum =
x*
x/x_twosig2 +
y*
y/y_twosig2 + z*z/z_twosig2;
9544 val = norm*exp(-sum);
9545 (*image)(ix,iy,iz) = val;
9557 LOGERR(
"%s wavelength is required parameter",
get_name().c_str());
9560 float wavelength =
params[
"wavelength"];
9567 float x = (float)(
nx/2);
9569 float y = (float)(
ny/2);
9571 float z = (float)(
nz/2);
9574 int ndim = image->get_ndim();
9577 for(
int j=0; j<
ny; ++j) {
9578 for(
int i=0; i<
nx; ++i) {
9579 float r=hypot(
x-(
float)i,
y-(
float)j);
9581 image->set_value_at(i,j,cos(2*(
float)pi*r/wavelength+
phase)/r);
9586 for(
int k=0; k<
nz; ++k) {
9587 for(
int j=0; j<
ny; ++j) {
9588 for(
int i=0; i<
nx; ++i) {
9591 image->set_value_at(i,j,k,cos(2*(
float)pi*r/wavelength+
phase)/(r*r));
9606 LOGERR(
"%s wavelength is required parameter",
get_name().c_str());
9609 float wavelength =
params[
"wavelength"];
9613 axis = (
const char*)
params[
"axis"];
9621 int ndim = image->get_ndim();
9622 float * dat = image->get_data();
9625 for(
int i=0; i<
nx; ++i, ++dat) {
9626 *dat = sin(i*(2.0f*M_PI/wavelength) +
phase);
9634 for(
int j=0; j<
ny; ++j) {
9635 for(
int i=0; i<
nx; ++i, ++dat) {
9637 *dat = sin((i*sin((180-alpha)*M_PI/180)+j*cos((180-alpha)*M_PI/180))*(2.0f*M_PI/wavelength) +
phase);
9639 else if(axis.compare(
"y")==0 || axis.compare(
"Y")==0) {
9640 *dat = sin(j*(2.0f*M_PI/wavelength) +
phase);
9643 *dat = sin(i*(2.0f*M_PI/wavelength) +
phase);
9662 for(
int k=0; k<
nz; ++k) {
9663 for(
int j=0; j<
ny; ++j) {
9664 for(
int i=0; i<
nx; ++i, ++dat) {
9665 if(axis.compare(
"z")==0 || axis.compare(
"Z")==0) {
9666 *dat = sin(k*(2.0f*M_PI/wavelength) +
phase);
9668 else if(axis.compare(
"y")==0 || axis.compare(
"Y")==0) {
9669 *dat = sin(j*(2.0f*M_PI/wavelength) +
phase);
9672 *dat = sin(i*(2.0f*M_PI/wavelength) +
phase);
9678 if(az != 0 || alt != 0 || phi != 0) {
9679 Dict d(
"type",
"eman");
9680 d[
"az"] = az; d[
"phi"] = phi; d[
"alt"] = alt;
9692 float wavelength =
params[
"wavelength"];
9693 string axis = (
const char*)
params[
"axis"];
9697 float *dat = image->get_data();
9700 for (
int k = 0; k <
nz; ++k) {
9701 for (
int j = 0; j <
ny; ++j) {
9702 for (
int i = 0; i <
nx; ++i, ++dat) {
9703 x2 = (float)( i -
nx/2 );
9704 y2 = (float)( j -
ny/2 );
9705 z2 = (float)( k -
nz/2 );
9707 r = (float)
sqrt(x2*x2+y2*y2+z2*z2);
9709 else if(axis ==
"x"){
9712 r = ( (float)
sqrt((x2-lc)*(x2-lc)+y2*y2+z2*z2) +
9713 (float)
sqrt((x2-rc)*(x2-rc)+y2*y2+z2*z2) ) /2.0f - c;
9715 else if(axis ==
"y"){
9718 r = ( (float)
sqrt(x2*x2+(y2-lc)*(y2-lc)+z2*z2) +
9719 (float)
sqrt(x2*x2+(y2-rc)*(y2-rc)+z2*z2) ) /2.0f - c;
9721 else if(axis ==
"z"){
9727 r = ( (float)
sqrt(x2*x2+y2*y2+(z2-lc)*(z2-lc)) +
9728 (float)
sqrt(x2*x2+y2*y2+(z2-rc)*(z2-rc)) ) /2.0f - c;
9733 *dat = sin( r * (2.0f*M_PI/wavelength) -
phase*180/M_PI);
9745 float edge_length =
params[
"edge_length"];
9746 string axis = (
const char*)
params[
"axis"];
9747 float odd_edge =
params[
"odd_edge"];
9750 fill = (int)
params[
"fill"];
9753 float *dat = image->get_data();
9755 float xEdge, yEdge, zEdge;
9757 xEdge = edge_length/2.0f;
9758 yEdge = edge_length/2.0f;
9759 zEdge = edge_length/2.0f;
9761 else if(axis ==
"x"){
9762 xEdge = odd_edge/2.0f;
9763 yEdge = edge_length/2.0f;
9764 zEdge = edge_length/2.0f;
9766 else if(axis ==
"y"){
9767 xEdge = edge_length/2.0f;
9768 yEdge = odd_edge/2.0f;
9769 zEdge = edge_length/2.0f;
9771 else if(axis ==
"z"){
9775 xEdge = edge_length/2.0f;
9776 yEdge = edge_length/2.0f;
9777 zEdge = odd_edge/2.0f;
9782 for (
int k = 0; k <
nz; ++k) {
9783 for (
int j = 0; j <
ny; ++j) {
9784 for (
int i = 0; i <
nx; ++i, ++dat) {
9785 x2 = (float)fabs((
float)i -
nx/2);
9786 y2 = (float)fabs((
float)j -
ny/2);
9787 z2 = (float)fabs((
float)k -
nz/2);
9788 if( x2<=xEdge && y2<=yEdge && z2<=zEdge ) {
9816 string axis = (
const char*)
params[
"axis"];
9820 float *dat = image->get_data();
9827 else if(axis ==
"x" || axis ==
"y"){
9840 for (
int k = 0; k <
nz; ++k) {
9841 for (
int j = 0; j <
ny; ++j) {
9842 for (
int i = 0; i <
nx; ++i, ++dat) {
9843 x2 = fabs((
float)i -
nx/2);
9844 y2 = fabs((
float)j -
ny/2);
9845 z2 = fabs((
float)k -
nz/2);
9847 r = (x2*x2)/(radius*radius) + (y2*y2)/(radius*radius) + (z2*z2)/(radius*radius);
9849 else if (axis ==
"x"){
9850 r = (x2*x2)/(asy*asy) + (y2*y2)/(radius*radius) + (z2*z2)/(radius*radius);
9852 else if(axis ==
"y"){
9853 r = (x2*x2)/(radius*radius) + (y2*y2)/(asy*asy) + (z2*z2)/(radius*radius);
9856 r = (x2*x2)/(radius*radius) + (y2*y2)/(radius*radius) + (z2*z2)/(asy*asy);
9905 int mz = 2*(int)c2+1;
9906 if (
nz < mz ) mz =
nz;
9907 int my = 2*(int)b2+1;
9908 if (
ny < my ) my =
ny;
9909 int mx = 2*(int)a2+1;
9910 if (
nx < mx ) mx =
nx;
9912 float ai1 = 1/(a1*a1);
9913 float bi1 = 1/(b1*b1);
9914 float ci1 = 1/(c1*c1);
9916 float ai2 = 1/(a2*a2);
9917 float bi2 = 1/(b2*b2);
9918 float ci2 = 1/(c2*c2);
9922 float x2, y2, z2, r1,r2;
9924 for (
int k = 0; k < mz; ++k) {
9925 for (
int j = 0; j < my; ++j) {
9926 for (
int i = 0; i < mx; ++i) {
9927 x2 = (float)(i - mx/2);
9928 y2 = (float)(j - my/2);
9929 z2 = (float)(k - mz/2);
9930 r1 = (x2*x2)*ai1 + (y2*y2)*bi1 + (z2*z2)*ci1;
9931 r2 = (x2*x2)*ai2 + (y2*y2)*bi2 + (z2*z2)*ci2;
9932 if (r2 <= 1 && r1 >= 1) {
9942 for(
int kk = -1; kk <= 1; ++kk)
9943 for(
int jj = -1; jj <= 1; ++jj)
9944 for(
int ii = -1; ii <= 1; ++ii) {
9948 if (xl >= 0 && xl < nx && yl >= 0 && yl < ny && zl >= 0 && zl <
nz)
9949 image->set_value_at(xl,yl,zl,1.0);
9952 image->set_value_at((
int)x2+
nx/2,(int)y2+
ny/2,(
int)z2+
nz/2,fill);
9983 int mz = 2*(int)c+1;
9984 if (
nz < mz ) mz =
nz;
9985 int my = 2*(int)b+1;
9986 if (
ny < my ) my =
ny;
9987 int mx = 2*(int)a+1;
9988 if (
nx < mx ) mx =
nx;
9997 float x2, y2, z2, r;
9999 for (
int k = 0; k < mz; ++k) {
10000 for (
int j = 0; j < my; ++j) {
10001 for (
int i = 0; i < mx; ++i) {
10002 x2 = (float)(i - mx/2);
10003 y2 = (float)(j - my/2);
10004 z2 = (float)(k - mz/2);
10005 r = (x2*x2)*ai + (y2*y2)*bi + (z2*z2)*ci;
10016 for(
int kk = -1; kk <= 1; ++kk)
10017 for(
int jj = -1; jj <= 1; ++jj)
10018 for(
int ii = -1; ii <= 1; ++ii) {
10022 if (xl >= 0 && xl < nx && yl >= 0 && yl < ny && zl >= 0 && zl <
nz)
10023 image->set_value_at(xl,yl,zl,fill);
10026 image->set_value_at((
int)x2+
nx/2,(int)y2+
ny/2,(
int)z2+
nz/2,fill);
10047 float *dat = image->get_data();
10048 size_t size = (size_t)
nx*
ny*
nz;
10049 for (
size_t i=0; i<size; ++i) {
10060 float sigma =
params[
"sigma"];
10061 if (sigma<=0) { sigma = 1.0; }
10062 float mean =
params[
"mean"];
10069 float *dat = image->get_data();
10070 size_t size = (size_t)
nx*
ny*
nz;
10071 for (
size_t i=0; i<size; ++i) {
10082 int nx = image->get_xsize();
10083 int ny = image->get_ysize();
10084 int nz = image->get_zsize();
10090 float radius =
params[
"radius"];
10098 height =
params[
"height"];
10104 height =
static_cast<float>(
nz);
10107 float *dat = image->get_data();
10110 for (
int k = 0; k <
nz; ++k) {
10111 for (
int j = 0; j <
ny; ++j) {
10112 for (
int i = 0; i <
nx; ++i, ++dat) {
10113 x2 = fabs((
float)i -
nx/2);
10114 y2 = fabs((
float)j -
ny/2);
10115 r = (x2*x2)/(radius*radius) + (y2*y2)/(radius*radius);
10117 if(r<=1 && k>=(
nz-height)/2 && k<=(
nz+height)/2) {
10134 int nx = image->get_xsize();
10135 int ny = image->get_ysize();
10136 int nz = image->get_zsize();
10142 float a =
params[
"major"];
10148 float b =
params[
"minor"];
10162 h =
static_cast<float>(
nz);
10165 float *dat = image->get_data();
10168 for (
int k = 0; k <
nz; ++k) {
10169 for (
int j = 0; j <
ny; ++j) {
10170 for (
int i = 0; i <
nx; ++i, ++dat) {
10171 x2 = fabs((
float)i -
nx/2);
10172 y2 = fabs((
float)j -
ny/2);
10173 r = (x2*x2)/(a*a) + (y2*y2)/(b*b);
10174 if(r<=1 && k>=(
nz-h)/2 && k<=(
nz+h)/2) {
10193 int nz = image->get_zsize();
10195 LOGERR(
"%s Processor doesn't support 3D model",
get_name().c_str());
10199 int nsam = image->get_xsize();
10200 int nrow = image->get_ysize();
10202 double sx1 = double(n1)*double(nsam+1);
10203 if ( nsam % 2 == 1 )
10207 double sx2 = double(n2)*double(nrow+1);
10208 if ( nrow % 2 == 1 )
10211 float *data = image->get_data();
10214 double syx1 = 0, syx2 = 0, sy = 0, sx1q = 0, sx2q = 0, syq = 0;
10215 for (
int j=1; j <= nrow; j++) {
10216 row = data + (j-1)*nsam - 1;
10217 for (
int i=1; i<=nsam; i++) {
10223 syq += row[i]*double(row[i]);
10227 float dn = float(nsam)*float(nrow);
10228 double qyx1 = syx1 - sx1*sy / dn;
10229 double qyx2 = syx2 - sx2*sy / dn;
10230 double qx1x2 = 0.0;
10231 double qx1 = sx1q - sx1*sx1 / dn;
10232 double qx2 = sx2q - sx2*sx2 / dn;
10233 double qy = syq - sy*sy / dn;
10234 double c = qx1*qx2 - qx1x2*qx1x2;
10235 if ( c > FLT_EPSILON ) {
10236 double b1 = (qyx1*qx2 - qyx2*qx1x2) / c;
10237 double b2 = (qyx2*qx1 - qyx1*qx1x2) / c;
10238 double a = (sy - b1*sx1 - b2*sx2) / dn;
10239 double d = a + b1 + b2;
10240 for (
int i=1; i<=nrow; i++) {
10242 row = data + (i-1)*nsam - 1;
10243 for (
int k=1; k<=nsam; k++) {
10244 row[k] -=
static_cast<float>(qy);
10262 if (image->get_zsize() > 1) {
10268 int xs = image->get_xsize();
10269 int ys = image->get_ysize();
10272 int width =
params[
"width"];
10274 width%=(xs > ys ? xs/2 : ys/2);
10280 float *left, *right, *top, *bottom;
10283 temp= (
double*)malloc((xs > ys ? xs*width : ys*width)*
sizeof(double));
10286 Log::logger()->
error(
"Could not allocate enough memory during call to CCDNorm\n");
10293 double mL,mR,mT,mB;
10296 double nl,nr,nt,nb;
10299 double q1,q2,q3,q4;
10302 for (z=0; z<width; z++) {
10303 left = image->get_col(xs/2 -1-z)->get_data();
10304 for (
y=0;
y<ys;
y++)
10305 temp[z*ys+
y]=left[
y];
10307 mL=gsl_stats_mean(temp,1,ys*width);
10309 for (z=0; z<width; z++) {
10310 right = image->get_col(xs/2 +z)->get_data();
10311 for (
y=0;
y<ys;
y++)
10312 temp[z*ys+
y]=right[
y];
10314 mR=gsl_stats_mean(temp,1,ys*width);
10316 for (z=0; z<width; z++) {
10317 top = image->get_row(ys/2 -1-z)->get_data();
10318 for (
x=0;
x<xs;
x++)
10319 temp[z*xs+
x]=top[
x];
10321 mT=gsl_stats_mean(temp,1,xs*width);
10323 for (z=0; z<width; z++) {
10324 bottom = image->get_row(ys/2 +z)->get_data();
10325 for (
x=0;
x<xs;
x++)
10326 temp[z*xs+
x]=bottom[
x];
10328 mB=gsl_stats_mean(temp,1,xs*width);
10343 for (
x = 0;
x < xs / 2;
x++)
10344 for (
y = 0;
y < ys / 2;
y++) {
10345 image->set_value_at_fast(
x,
y, image->get_value_at(
x,
y) +
static_cast<float>(q1));
10347 for (
x = xs / 2;
x < xs;
x++)
10348 for (
y = 0;
y < ys / 2;
y++) {
10349 image->set_value_at_fast(
x,
y, image->get_value_at(
x,
y) +
static_cast<float>(q2));
10351 for (
x = xs / 2;
x < xs;
x++)
10352 for (
y = ys / 2;
y < ys;
y++) {
10353 image->set_value_at_fast(
x,
y, image->get_value_at(
x,
y) +
static_cast<float>(q3));
10355 for (
x = 0;
x < xs / 2;
x++)
10356 for (
y = ys / 2;
y < ys;
y++) {
10357 image->set_value_at_fast(
x,
y, image->get_value_at(
x,
y) +
static_cast<float>(q4));
10364 int nx=image->get_xsize();
10365 int nz=image->get_xsize();
10366 EMData * result = image->process(
"filter.highpass.gauss",
Dict(
"cutoff_freq",0.01f));
10367 if (nz==1) result->process_inplace(
"mask.decayedge2d",
Dict(
"width",nx/50));
10368 result->add(-
float(result->get_attr(
"minimum")));
10369 result->process_inplace(
"filter.lowpass.tophat",
Dict(
"cutoff_freq",0.05));
10370 result->process_inplace(
"math.squared");
10371 result->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_freq",10.0f/(nx/40*(
float)image->get_attr(
"apix_x"))));
10372 result->process_inplace(
"normalize.edgemean");
10381 memcpy(image->get_data(),tmp->get_data(),image->get_size()*
sizeof(
float));
10389 if (image->get_zsize() != 1) {
10395 const gsl_wavelet_type * T;
10396 nx=image->get_xsize();
10397 ny=image->get_ysize();
10407 double *cpy = (
double *)malloc(nx*ny*
sizeof(
double));
10409 for (i=0; i<nx*ny; i++) cpy[i]=image->get_value_at(i,0,0);
10411 string tp = (
const char*)
params[
"type"];
10412 if (tp==
"daub") T=gsl_wavelet_daubechies;
10413 else if (tp==
"harr") T=gsl_wavelet_haar;
10414 else if (tp==
"bspl") T=gsl_wavelet_bspline;
10417 int K=(int)
params[
"ord"];
10418 gsl_wavelet_direction dir;
10420 if ((
int)
params[
"dir"]==1) dir=(gsl_wavelet_direction)1;
10421 else dir=(gsl_wavelet_direction)-1;
10423 gsl_wavelet *w = gsl_wavelet_alloc(T, K);
10424 gsl_wavelet_workspace *work = gsl_wavelet_workspace_alloc(nx);
10426 if (ny==1) gsl_wavelet_transform (w,cpy, 1, nx, dir, work);
10427 else gsl_wavelet2d_transform (w, cpy, nx,nx,ny, dir, work);
10429 gsl_wavelet_workspace_free (work);
10430 gsl_wavelet_free (w);
10432 for (i=0; i<nx*ny; i++) image->set_value_at_fast(i,0,0,
static_cast<float>(cpy[i]));
10440 if ((
int)
params[
"dir"]==-1||(image->is_complex() && (
int)
params[
"dir"]==0)) {
10441 image->do_ift_inplace();
10444 image->do_fft_inplace();
10538 string axis = (
const char*)
params[
"axis"];
10540 float* data = image->EMData::get_data();
10542 int nx = image->get_xsize();
10543 int ny = image->get_ysize();
10544 int nz = image->get_zsize();
10545 size_t nxy = nx*ny;
10551 if (axis ==
"x" || axis ==
"X") {
10553 for (
int iz = 0; iz < nz; iz++){
10554 for (
int iy = 0; iy < ny; iy++) {
10555 offset = nx*iy + nxy*iz;
10556 reverse(&data[x_start+offset],&data[offset+nx]);
10559 }
else if (axis ==
"y" || axis ==
"Y") {
10560 float *tmp =
new float[nx];
10563 for (
int iz = 0; iz < nz; iz++) {
10565 for (
int iy = y_start; iy < nhalf; iy++) {
10566 memcpy(tmp, &data[beg+iy*nx], nx*
sizeof(
float));
10567 memcpy(&data[beg+iy*nx], &data[beg+(y_start+ny-iy-1)*nx], nx*
sizeof(
float));
10568 memcpy(&data[beg+(y_start+ny-iy-1)*nx], tmp, nx*
sizeof(
float));
10572 }
else if (axis ==
"z" || axis ==
"Z") {
10575 float *tmp =
new float[nxy];
10576 for(
int iz = 0;iz<nhalf;iz++){
10577 memcpy(tmp,&data[iz*nxy],nxy*
sizeof(
float));
10578 memcpy(&data[iz*nxy],&data[(nz-iz-1)*nxy],nxy*
sizeof(
float));
10579 memcpy(&data[(nz-iz-1)*nxy],tmp,nxy*
sizeof(
float));
10583 float *tmp =
new float[nx];
10586 for (
int iy = 0; iy < ny; iy++) {
10588 for (
int iz = z_start; iz < nhalf; iz++) {
10589 memcpy(tmp, &data[beg+ iz*nxy], nx*
sizeof(
float));
10590 memcpy(&data[beg+iz*nxy], &data[beg+(nz-iz-1+z_start)*nxy], nx*
sizeof(
float));
10591 memcpy(&data[beg+(nz-iz-1+z_start)*nxy], tmp, nx*
sizeof(
float));
10608 string axis = (
const char*)params[
"axis"];
10610 float* data = image->EMData::get_data();
10612 int nx = image->get_xsize();
10613 int ny = image->get_ysize();
10614 int nz = image->get_zsize();
10615 size_t nxy = nx*ny;
10617 int x_start = 1-nx%2;
10618 int y_start = 1-ny%2;
10619 int z_start = 1-nz%2;
10621 if (axis ==
"x" || axis ==
"X") {
10622 if(image->is_complex()) {
10623 if(nz>1 || ny%2 == 1 || image->is_fftodd() )
throw ImageFormatException(
"Error: Mirror works only on 2D even complex images");
10624 for (
int iy = 1; iy < ny/2; iy++) {
10625 int offset = nx*iy;
10626 int off2 = nx*(ny-iy);
10627 for (
int ix = 0; ix < nx; ix++) {
10628 float tmp = data[ix+offset];
10629 data[ix+offset] = data[ix+off2];
10630 data[ix+off2] = tmp;
10634 for (
int ix = 1; ix < nxy; ix += 2) data[ix] = -data[ix];
10636 for (
int iz = 0; iz < nz; iz++)
10637 for (
int iy = 0; iy < ny; iy++) {
10638 int offset = nx*iy + nxy*iz;
10639 reverse(&data[offset+x_start],&data[offset+nx]);
10642 }
else if (axis ==
"y" || axis ==
"Y") {
10643 float *tmp =
new float[nx];
10646 for (
int iz = 0; iz < nz; iz++) {
10648 for (
int iy = y_start; iy < nhalf; iy++) {
10649 memcpy(tmp, &data[beg+iy*nx], nx*
sizeof(
float));
10650 memcpy(&data[beg+iy*nx], &data[beg+(ny-iy-1+y_start)*nx], nx*
sizeof(
float));
10651 memcpy(&data[beg+(ny-iy-1+y_start)*nx], tmp, nx*
sizeof(
float));
10655 }
else if (axis ==
"z" || axis ==
"Z") {
10658 float *tmp =
new float[nxy];
10659 for(
int iz = 0;iz<nhalf;iz++){
10660 memcpy(tmp,&data[iz*nxy],nxy*
sizeof(
float));
10661 memcpy(&data[iz*nxy],&data[(nz-iz-1)*nxy],nxy*
sizeof(
float));
10662 memcpy(&data[(nz-iz-1)*nxy],tmp,nxy*
sizeof(
float));
10666 float *tmp =
new float[nx];
10669 for (
int iy = 0; iy < ny; iy++) {
10671 for (
int iz = z_start; iz < nhalf; iz++) {
10672 memcpy(tmp, &data[beg+ iz*nxy], nx*
sizeof(
float));
10673 memcpy(&data[beg+iz*nxy], &data[beg+(nz-iz-1+z_start)*nxy], nx*
sizeof(
float));
10674 memcpy(&data[beg+(nz-iz-1+z_start)*nxy], tmp, nx*
sizeof(
float));
10688 Assert(processornames.size() > 0);
10690 for (
size_t i = 0; i < processornames.size(); i++) {
10691 image->process_inplace(processornames[i]);
10701 int nx = image->get_xsize();
10702 int ny = image->get_ysize();
10703 int nz = image->get_zsize();
10710 const float *
const src_data = image->get_const_data();
10713 if ((nz == 1)&&(image ->
is_real())) {
10714 Vec2f offset(nx/2,ny/2);
10715 for (
int j = 0; j < ny; j++) {
10716 for (
int i = 0; i < nx; i++) {
10717 Vec2f coord(i-nx/2,j-ny/2);
10718 Vec2f soln = inv*coord;
10721 float x2 = soln[0];
10722 float y2 = soln[1];
10724 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
10725 des_data[i + j * nx] = 0;
10731 int k0 = ii + jj * nx;
10734 int k3 = k0 + nx + 1;
10736 if (ii == nx - 1) {
10740 if (jj == ny - 1) {
10753 if ((nz == 1)&&(image ->
is_complex())&&(nx%2==0)&&((2*(nx-ny)-3)*(2*(nx-ny)-3)==1)&&(zerocorners==0) ) {
10770 float xshift= transNow[0];
float yshift= transNow[1];
10771 float tempR;
float tempI;
float tempW;
10774 Vec2f offset(nx/2,ny/2);
10775 float Mid =(N+1.0)/2.0;
10776 for (
int kyN = 0; kyN < ny; kyN++) {
10778 if (kyN>=nx/2) kyNew=kyN-ny;
10779 float kxOldPre= - sin(theta)* kyNew;
10780 float kyOldPre= cos(theta)* kyNew;
10781 float phaseY = -2*pi*kyNew*yshift/ny;
10783 for (
int kxN = 0; kxN < (nx/2); kxN++) {
10785 if (kxN >= nx/2) kxNew=kxN-ny;
10787 float kxOld= kxOldPre + cos(theta)* kxNew ;
10788 float kyOld= kyOldPre + sin(theta)* kxNew ;
10790 int kxLower= floor(kxOld);
int kxUpper= kxLower+1;
10791 int kyLower= floor(kyOld);
int kyUpper= kyLower+1;
10792 float dkxLower= (kxUpper-kxOld);
float dkxUpper= (kxOld-kxLower);
10793 float dkyLower= (kyUpper-kyOld);
float dkyUpper= (kyOld-kyLower);
10795 int kxL= kxLower;
int kyL=kyLower;
10796 float dataLL_R= 0;
float dataLL_I=0;
int flag=1;
10797 if ((abs(kxL)<Mid) && (abs(kyL)<Mid)) {
10798 kxL = (N+kxL)%N; kyL = (N+kyL)%N;
10799 if (kxL> N/2){ kxL=(N-kxL)%N; kyL=(N-kyL)%N ;flag=-1;}
10800 dataLL_R= src_data[2*kxL+ kyL*nx];
10801 dataLL_I= flag*src_data[2*kxL+1+ kyL*nx];
10804 kxL=kxLower;
int kyU=kyUpper;
10805 float dataLU_R= 0;
float dataLU_I=0; flag=1;
10806 if ((abs(kxL)<Mid) && (abs(kyU)<Mid)){
10807 kxL = (N+kxL)%N; kyU = (N+kyU)%N;
10808 if (kxL> N/2){ kxL=(N-kxL)%N; kyU=(N-kyU)%N;flag=-1;}
10809 dataLU_R= src_data[2*kxL+ kyU*nx];
10810 dataLU_I= flag*src_data[2*kxL+1+ kyU*nx];
10813 int kxU= kxUpper; kyL=kyLower;
10814 float dataUL_R= 0;
float dataUL_I=0; flag=1;
10815 if ((abs(kxU)<Mid) && (abs(kyL)<Mid)) {
10816 kxU = (N+kxU)%N; kyL = (N+kyL)%N;
10817 if (kxU> N/2) { kxU=(N-kxU)%N; kyL=(N-kyL)%N;flag=-1;}
10818 dataUL_R= src_data[2*kxU + kyL*nx];
10819 dataUL_I= flag*src_data[2*kxU+1 + kyL*nx];
10822 kxU= kxUpper; kyU=kyUpper;
10823 float dataUU_R= 0;
float dataUU_I=0; flag=1;
10824 if ((abs(kxU)<Mid) & (abs(kyU)<Mid)){
10825 kxU = (N+kxU)%N; kyU = (N+kyU)%N;
10826 if (kxU> N/2) { kxU=(N-kxU)%N; kyU=(N-kyU)%N;flag=-1;}
10827 dataUU_R= src_data[2*kxU + kyU*nx];
10828 dataUU_I= flag*src_data[2*kxU+1 + kyU*nx];
10831 float WLL = dkxLower*dkyLower ;
10832 float WLU = dkxLower*dkyUpper ;
10833 float WUL = dkxUpper*dkyLower ;
10834 float WUU = dkxUpper*dkyUpper ;
10835 tempW = WLL + WLU + WUL + WUU ;
10838 tempR = WLL*dataLL_R + WLU*dataLU_R + WUL* dataUL_R + WUU * dataUU_R ;
10839 tempI = WLL*dataLL_I + WLU*dataLU_I + WUL* dataUL_I + WUU * dataUU_I ;
10841 float phase = phaseY -2*pi*kxNew*xshift/ny;
10842 float tempRb=tempR*cos(
phase) - tempI*sin(
phase);
10843 float tempIb=tempR*sin(
phase) + tempI*cos(
phase);
10845 des_data[2*kxN + nx* kyN] = tempRb/tempW;
10846 des_data[2*kxN+1 + nx* kyN] = tempIb/tempW;
10853 if ((nz == 1)&&(image ->
is_complex())&&(nx%2==0)&&((2*(nx-ny)-3)*(2*(nx-ny)-3)==1)&&(zerocorners==1) ) {
10869 float Ctheta= cos(theta);
10870 float Stheta= sin(theta);
10873 float xshift= transNow[0];
float yshift= transNow[1];
10875 float tempR;
float tempI;
10879 Vec2f offset(nx/2,ny/2);
10880 float phaseConstx = -2*pi*xshift/ny ;
10881 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
10882 float k3= 1.0/k1;
float k4= k2/k1;
10885 for (
int kyN = 0; kyN < ny; kyN++) {
10887 if (kyN>=nx/2) kyNew=kyN-ny;
10888 float kxOld= - Stheta* kyNew - Ctheta;
10889 float kyOld= Ctheta* kyNew - Stheta;
10890 float phase = -2*pi*kyNew*yshift/ny - phaseConstx ;
10891 float Cphase = cos(
phase);
10892 float Sphase = sin(
phase);
10895 if (mirror==-1.0) {
10896 if (kyN>0) IndexOut = -2 + nx * (ny-kyN);
10897 else IndexOut = -2+ nx* kyN;
10899 else IndexOut = -2+ nx* kyN;
10900 for (
int kxN = 0; kxN < (nx/2); kxN++) {
10907 phase += phaseConstx;
10908 Cphase = Cphase*k1 -Sphase*k2;
10909 Sphase = Sphase*k3+ Cphase*k4;
10913 des_data[IndexOut] = 0;
10914 des_data[IndexOut+1] = 0;
10918 int kxLower= floor(kxOld);
10919 int kyLower= floor(kyOld);
10921 float dkxUpper= (kxOld-kxLower);
10923 float dkyUpper= (kyOld-kyLower);
10925 kx= kxLower; ky =kyLower;
10929 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagLL=-1;}
10930 int kLL =2*kx+ky*nx;
10932 kx = kxLower; ky = kyLower+1;
10936 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagLU=-1;}
10937 int kLU =2*kx+ky*nx;
10939 kx = kxLower+1; ky=kyLower;
10943 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagUL=-1;}
10944 int kUL =2*kx+ky*nx;
10946 kx = kxLower+1; ky = kyLower+1;
10950 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagUU=-1;}
10951 int kUU =2*kx+ky*nx;
10961 if (kLL<0||kUL<0||kLU<0||kUU<0||kLL>=nxy||kUL>=nxy||kLU>=nxy||kUU>=nxy)
continue;
10968 flagLU*src_data[kLU+1], flagUU*src_data[kUU+1],dkxUpper,dkyUpper);
10972 float tempRb=tempR*Cphase - tempI*Sphase;
10973 float tempIb=tempR*Sphase + tempI*Cphase;
10975 des_data[IndexOut] = tempRb;
10977 des_data[IndexOut+1] = tempIb*mirror;
10984 if ((nz > 1)&&(image ->
is_complex())&&(zerocorners==3)) {
10990 float xshift= transNow[0];
float yshift= transNow[1];
float zshift= transNow[2];
10992 float phaseConstx = -2*pi*xshift/ny ;
10993 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
10994 float k3= 1.0/k1;
float k4= k2/k1;
10996 float MatXX = (cos(az)*cos(phi) - sin(az)*cos(alt)*sin(phi) );
10997 float MatXY = (- cos(az)*sin(phi) - sin(az)*cos(alt)*cos(phi) ) ;
10998 float MatXZ = sin(az)*sin(alt) ;
10999 float MatYX = (sin(az)*cos(phi) + cos(az)*cos(alt)*sin(phi) );
11000 float MatYY = (- sin(az)*sin(phi) + cos(az)*cos(alt)*cos(phi) ) ;
11001 float MatYZ = - cos(az)*sin(alt) ;
11002 float MatZX = sin(alt)*sin(phi);
11003 float MatZY = sin(alt)*cos(phi);
11004 float MatZZ = cos(alt) ;
11005 float tempR;
float tempI;
float tempW;
11006 float Mid =(N+1.0)/2.0;
11009 for (
int kzN = 0; kzN < ny; kzN++) {
11011 if (kzN >= nx/2) kzNew=kzN-N;
11012 for (
int kyN = 0; kyN < ny; kyN++) {
11014 if (kyN>=nx/2) kyNew=kyN-ny;
11015 float kxPre = MatXY * kyNew + MatXZ *kzNew;
11016 float kyPre = MatYY * kyNew + MatYZ*kzNew;
11017 float kzPre = MatZY * kyNew + MatZZ*kzNew;
11018 float phase = -2*pi*kzNew*zshift/ny-2*pi*kyNew*yshift/ny - phaseConstx ;
11019 float Cphase = cos(
phase);
11020 float Sphase = sin(
phase);
11022 float OutBounds2= (2*Mid*Mid- (kyNew*kyNew+kzNew*kzNew)) ;
11023 int kxNewMax= nx/2;
11024 if (OutBounds2< 0) kxNewMax=0;
11025 else if (OutBounds2<(nx*nx/4)) kxNewMax=
sqrt(OutBounds2);
11026 for (
int kxN = kxNewMax; kxN < nx/2 ; kxN++ ) {
11027 des_data[2*kxN + nx* kyN +nxny*kzN] = 0;
11028 des_data[2*kxN + nx* kyN +nxny*kzN+1] = 0;
11032 for (
int kxN = 0; kxN < kxNewMax; kxN++ ) {
11033 Cphase = Cphase*k1 -Sphase*k2;
11034 Sphase = Sphase*k3+ Cphase*k4;
11036 float kxOld= MatXX * kxN + kxPre;
11037 float kyOld= MatYX * kxN + kyPre;
11038 float kzOld= MatZX * kxN + kzPre;
11040 if ((abs(kxOld)>=Mid) || (abs(kyOld)>=Mid) || (abs(kzOld)>=Mid) ) {
11041 des_data[2*kxN + nx* kyN +nxny*kzN] = 0;
11042 des_data[2*kxN + nx* kyN +nxny*kzN+1] = 0;
11045 int kxLower= floor(kxOld);
int kxUpper= kxLower+1;
11046 int kyLower= floor(kyOld);
int kyUpper= kyLower+1;
11047 int kzLower= floor(kzOld);
int kzUpper= kzLower+1;
11049 float dkxLower= (kxUpper-kxOld);
float dkxUpper= (kxOld-kxLower);
11050 float dkyLower= (kyUpper-kyOld);
float dkyUpper= (kyOld-kyLower);
11051 float dkzLower= (kzUpper-kzOld);
float dkzUpper= (kzOld-kzLower);
11053 int kxL= kxLower;
int kyL=kyLower;
int kzL=kzLower;
11054 float dataLLL_R= 0;
float dataLLL_I=0;
int flag=1;
11055 if ( (abs(kxL)<Mid) && (abs(kyL)<Mid) && (abs(kzL)<Mid) ) {
11056 kxL = (N+kxL)%N; kyL = (N+kyL)%N; kzL = (N+kzL)%N;
11057 if (kxL> N/2){kxL=(N-kxL)%N; kyL=(N-kyL)%N ; kzL=(N-kzL)%N ;flag=-1;}
11058 dataLLL_R= src_data[ 2*kxL + nx*kyL+ nxny*kzL ];
11059 dataLLL_I=flag*src_data[ 2*kxL+1 + nx*kyL+ nxny*kzL ];
11062 kxL= kxLower; kyL=kyLower;
int kzU=kzUpper;
11063 float dataLLU_R= 0;
float dataLLU_I=0; flag=1;
11064 if ( (abs(kxL)<Mid) && (abs(kyL)<Mid) && (abs(kzU)<Mid) ) {
11065 kxL = (N+kxL)%N; kyL = (N+kyL)%N; kzU = (N+kzU)%N;
11066 if (kxL> N/2){kxL=(N-kxL)%N; kyL=(N-kyL)%N ; kzU=(N-kzU)%N ;flag=-1;}
11067 dataLLU_R= src_data[ 2*kxL + nx*kyL+ nxny*kzU ];
11068 dataLLU_I= flag*src_data[ 2*kxL+1 + nx*kyL+ nxny*kzU ];
11071 kxL= kxLower;
int kyU=kyUpper; kzL=kzLower;
11072 float dataLUL_R= 0;
float dataLUL_I=0; flag=1;
11073 if ( (abs(kxL)<Mid) && (abs(kyU)<Mid)&& (abs(kzL)<Mid) ) {
11074 kxL = (N+kxL)%N; kyU = (N+kyU)%N; kzL = (N+kzL)%N;
11075 if (kxL> N/2){ kxL=(N-kxL)%N; kyU=(N-kyU)%N; kzL=(N-kzL)%N ;flag=-1;}
11076 dataLUL_R= src_data[ 2*kxL + nx*kyU+ nxny*kzL ];
11077 dataLUL_I=flag*src_data[ 2*kxL+1 + nx*kyU+ nxny*kzL ];
11080 kxL= kxLower; kyU=kyUpper; kzL=kzUpper;
11081 float dataLUU_R= 0;
float dataLUU_I=0; flag=1;
11082 if ( (abs(kxL)<Mid) && (abs(kyU)<Mid)&& (abs(kzU)<Mid)) {
11083 kxL = (N+kxL)%N; kyU = (N+kyU)%N; kzU = (N+kzU)%N;
11084 if (kxL> N/2){kxL=(N-kxL)%N; kyU=(N-kyU)%N; kzL=(N-kzL)%N ;flag=-1;}
11085 dataLUU_R= src_data[ 2*kxL + nx*kyU+ nxny*kzU ];
11086 dataLUU_I=flag*src_data[ 2*kxL+1 + nx*kyU+ nxny*kzU ];
11089 int kxU= kxUpper; kyL=kyLower; kzL=kzLower;
11090 float dataULL_R= 0;
float dataULL_I=0; flag=1;
11091 if ( (abs(kxU)<Mid) && (abs(kyL)<Mid) && (abs(kzL)<Mid) ) {
11092 kxU = (N+kxU)%N; kyL = (N+kyL)%N; kzL = (N+kzL)%N;
11093 if (kxU> N/2){kxU=(N-kxU)%N; kyL=(N-kyL)%N; kzL=(N-kzL)%N ;flag=-1;}
11094 dataULL_R= src_data[ 2*kxU + nx*kyL+ nxny*kzL ];
11095 dataULL_I=flag*src_data[ 2*kxU+1 + nx*kyL+ nxny*kzL ];
11098 kxU= kxUpper; kyL=kyLower; kzU=kzUpper;
11099 float dataULU_R= 0;
float dataULU_I=0; flag=1;
11100 if ( (abs(kxU)<Mid) && (abs(kyL)<Mid)&& (abs(kzU)<Mid) ) {
11101 kxU = (N+kxU)%N; kyL = (N+kyL)%N; kzU = (N+kzU)%N;
11102 if (kxU> N/2){kxU=(N-kxU)%N; kyL=(N-kyL)%N; kzU=(N-kzU)%N ;flag=-1;}
11103 dataULU_R= src_data[ 2*kxU + nx*kyL+ nxny*kzU ];
11104 dataULU_I=flag*src_data[ 2*kxU+1 + nx*kyL+ nxny*kzU ];
11107 kxU= kxUpper; kyU=kyUpper; kzL=kzLower;
11108 float dataUUL_R= 0;
float dataUUL_I=0; flag=1;
11109 if ( (abs(kxU)<Mid) && (abs(kyU)<Mid) && (abs(kzL)<Mid) ) {
11110 kxU = (N+kxU)%N; kyU = (N+kyU)%N; kzL = (N+kzL)%N;
11111 if (kxU> N/2){kxU=(N-kxU)%N; kyU=(N-kyU)%N; kzL=(N-kzL)%N ;flag=-1;}
11112 dataUUL_R= src_data[ 2*kxU + nx*kyU+ nxny*kzL ];
11113 dataUUL_I=flag*src_data[ 2*kxU+1 + nx*kyU+ nxny*kzL ];
11116 kxU= kxUpper; kyU=kyUpper; kzU=kzUpper;
11117 float dataUUU_R= 0;
float dataUUU_I=0; flag=1;
11118 if ( (abs(kxU)<Mid) && (abs(kyU)<Mid) && (abs(kzU)<Mid) ) {
11119 kxU = (N+kxU)%N; kyU = (N+kyU)%N; kzU = (N+kzU)%N;
11120 if (kxU> N/2) {kxU=(N-kxU)%N; kyU=(N-kyU)%N; kzU=(N-kzU)%N ;flag=-1;}
11121 dataUUU_R= src_data[ 2*kxU + nx*kyU+ nxny*kzU ];
11122 dataUUU_I=flag*src_data[ 2*kxU+1 + nx*kyU+ nxny*kzU ];
11125 float WLLL = dkxLower*dkyLower*dkzLower ;
11128 float WLLU = dkxLower*dkyLower*dkzUpper ;
11129 float WLUL = dkxLower*dkyUpper*dkzLower ;
11130 float WLUU = dkxLower*dkyUpper*dkzUpper ;
11131 float WULL = dkxUpper*dkyLower*dkzLower ;
11132 float WULU = dkxUpper*dkyLower*dkzUpper ;
11133 float WUUL = dkxUpper*dkyUpper*dkzLower;
11134 float WUUU = dkxUpper*dkyUpper*dkzUpper;
11135 tempW = WLLL + WLLU + WLUL + WLUU + WULL + WULU + WUUL + WUUU ;
11137 tempR = WLLL*dataLLL_R + WLLU*dataLLU_R + WLUL*dataLUL_R + WLUU*dataLUU_R ;
11138 tempR += WULL*dataULL_R + WULU*dataULU_R + WUUL*dataUUL_R + WUUU*dataUUU_R ;
11140 tempI = WLLL*dataLLL_I + WLLU*dataLLU_I + WLUL*dataLUL_I + WLUU*dataLUU_I ;
11141 tempI += WULL*dataULL_I + WULU*dataULU_I + WUUL*dataUUL_I + WUUU*dataUUU_I ;
11144 float tempRb=tempR*Cphase - tempI*Sphase;
11145 float tempIb=tempR*Sphase + tempI*Cphase;
11147 des_data[2*kxN + nx* kyN +nxny*kzN] = tempRb/tempW;
11148 des_data[2*kxN+1 + nx* kyN +nxny*kzN] = tempIb/tempW;
11152 if ((nz > 1)&&(image ->
is_complex())&&(zerocorners==2)) {
11158 float xshift= transNow[0];
float yshift= transNow[1];
float zshift= transNow[2];
11160 float phaseConstx = -2*pi*xshift/ny ;
11161 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
11162 float k3= 1.0/k1;
float k4= k2/k1;
11164 float MatXX = (cos(az)*cos(phi) - sin(az)*cos(alt)*sin(phi) );
11165 float MatXY = (- cos(az)*sin(phi) - sin(az)*cos(alt)*cos(phi) ) ;
11166 float MatXZ = sin(az)*sin(alt) ;
11167 float MatYX = (sin(az)*cos(phi) + cos(az)*cos(alt)*sin(phi) );
11168 float MatYY = (- sin(az)*sin(phi) + cos(az)*cos(alt)*cos(phi) ) ;
11169 float MatYZ = - cos(az)*sin(alt) ;
11170 float MatZX = sin(alt)*sin(phi);
11171 float MatZY = sin(alt)*cos(phi);
11172 float MatZZ = cos(alt) ;
11174 float Mid =(N+1.0)/2.0;
11175 int lim=(N/2)*(N/2);
11178 for (
int kzN = 0; kzN < ny; kzN++) {
11180 if (kzN >= nx/2) kzNew=kzN-N;
11181 for (
int kyN = 0; kyN < ny; kyN++) {
11183 if (kyN>=nx/2) kyNew=kyN-ny;
11186 int kyz2=kyNew*kyNew+kzNew*kzNew;
11187 if (kyz2>lim)
continue;
11188 int kxNewMax=(int)floor(
sqrt((
float)(lim-kyz2)));
11189 float kxPre = MatXY * kyNew + MatXZ *kzNew;
11190 float kyPre = MatYY * kyNew + MatYZ*kzNew;
11191 float kzPre = MatZY * kyNew + MatZZ*kzNew;
11192 float phase = -2*pi*kzNew*zshift/ny-2*pi*kyNew*yshift/ny - phaseConstx ;
11193 float Cphase = cos(
phase);
11194 float Sphase = sin(
phase);
11202 for (
int kxN = 0; kxN < kxNewMax; kxN++ ) {
11203 Cphase = Cphase*k1 -Sphase*k2;
11204 Sphase = Sphase*k3+ Cphase*k4;
11206 float kxOld= MatXX * kxN + kxPre;
11207 float kyOld= MatYX * kxN + kyPre;
11208 float kzOld= MatZX * kxN + kzPre;
11216 int kx0= floor(kxOld);
11217 int ky0= floor(kyOld);
11218 int kz0= floor(kzOld);
11220 float dkx0= (kxOld-kx0);
11221 float dky0= (kyOld-ky0);
11222 float dkz0= (kzOld-kz0);
11224 std::complex<float> c0 = image->get_complex_at(kx0 ,ky0 ,kz0 );
11225 std::complex<float> c1 = image->get_complex_at(kx0+1,ky0 ,kz0 );
11226 std::complex<float> c2 = image->get_complex_at(kx0 ,ky0+1,kz0 );
11227 std::complex<float> c3 = image->get_complex_at(kx0+1,ky0+1,kz0 );
11228 std::complex<float> c4 = image->get_complex_at(kx0 ,ky0 ,kz0+1);
11229 std::complex<float> c5 = image->get_complex_at(kx0+1,ky0 ,kz0+1);
11230 std::complex<float> c6 = image->get_complex_at(kx0 ,ky0+1,kz0+1);
11231 std::complex<float> c7 = image->get_complex_at(kx0+1,ky0+1,kz0+1);
11233 std::complex<float> nwv =
Util::trilinear_interpolate_complex(c0,c1,c2,c3,c4,c5,c6,c7,dkx0,dky0,dkz0);
11235 des_data[2*kxN + nx* kyN +nxny*kzN] = nwv.real()*Cphase - nwv.imag()*Sphase;
11236 des_data[2*kxN+1 + nx* kyN +nxny*kzN] = nwv.real()*Sphase + nwv.imag()*Cphase;
11337 if ((nz > 1)&&(image ->
is_complex())&&(zerocorners<=1)) {
11343 float xshift= transNow[0];
float yshift= transNow[1];
float zshift= transNow[2];
11345 float MatXX = (cos(az)*cos(phi) - sin(az)*cos(alt)*sin(phi) );
11346 float MatXY = (- cos(az)*sin(phi) - sin(az)*cos(alt)*cos(phi) ) ;
11347 float MatXZ = sin(az)*sin(alt) ;
11348 float MatYX = (sin(az)*cos(phi) + cos(az)*cos(alt)*sin(phi) );
11349 float MatYY = (- sin(az)*sin(phi) + cos(az)*cos(alt)*cos(phi) ) ;
11350 float MatYZ = - cos(az)*sin(alt) ;
11351 float MatZX = sin(alt)*sin(phi);
11352 float MatZY = sin(alt)*cos(phi);
11353 float MatZZ = cos(alt) ;
11354 float tempR=0;
float tempI=0;
11355 float Mid =(N+1.0)/2.0;
11356 float phaseConstx = -2*pi*xshift/ny ;
11357 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
11358 float k3= 1.0/k1;
float k4= k2/k1;
11365 for (
int kzN = 0; kzN < ny; kzN++) {
11367 if (kzN >= nx/2) kzNew=kzN-N;
11368 for (
int kyN = 0; kyN < ny; kyN++) {
11370 if (kyN>=nx/2) kyNew=kyN-ny;
11372 float kxOld = MatXY * kyNew + MatXZ *kzNew - MatXX;
11373 float kyOld = MatYY * kyNew + MatYZ*kzNew - MatYX;
11374 float kzOld = MatZY * kyNew + MatZZ*kzNew - MatZX;
11375 float phase = -2*pi*kzNew*zshift/ny-2*pi*kyNew*yshift/ny - phaseConstx ;
11376 float Cphase = cos(
phase);
11377 float Sphase = sin(
phase);
11380 int IndexOut= -2+ nx* kyN +nxny*kzN;
11381 float OutBounds2 = (Mid*Mid- (kyOld*kyOld+kzOld*kzOld)) ;
11383 int kxNewMax= nx/2;
11384 if (OutBounds2< 0) kxNewMax=0;
11385 else if (OutBounds2<(nx*nx/4)) kxNewMax=
sqrt(OutBounds2);
11386 for (
int kxN = kxNewMax; kxN < nx/2 ; kxN++ ) {
11387 des_data[2*kxN + nx* kyN +nxny*kzN] = 0;
11388 des_data[2*kxN + nx* kyN +nxny*kzN+1] = 0;
11392 for (
int kxNew = 0; kxNew < kxNewMax; kxNew++ ) {
11401 phase += phaseConstx;
11402 Cphase = Cphase*k1 -Sphase*k2;
11403 Sphase = Sphase*k3+ Cphase*k4;
11406 if ((abs(kxOld)>=Mid) || (abs(kyOld)>=Mid) || (abs(kzOld)>=Mid) ) {
11407 des_data[IndexOut] = 0;
11408 des_data[IndexOut+1] = 0;
11415 int kxLower= floor(kxOld);
11416 int kyLower= floor(kyOld);
11417 int kzLower= floor(kzOld);
11419 float dkxUpper= (kxOld-kxLower);
11420 float dkyUpper= (kyOld-kyLower);
11421 float dkzUpper= (kzOld-kzLower);
11424 kx= kxLower; ky =kyLower; kz=kzLower;
11428 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11429 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLLL=-1;}
11430 int kLLL =2*kx + nx*ky+ nxny*kz ;
11436 kx= kxLower; ky =kyLower; kz=kzLower+1;
11440 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11441 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLLU=-1;}
11442 int kLLU =2*kx + nx*ky+ nxny*kz ;
11448 kx= kxLower; ky =kyLower+1; kz=kzLower;
11452 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11453 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLUL=-1;}
11454 int kLUL =2*kx + nx*ky+ nxny*kz ;
11460 kx= kxLower; ky =kyLower+1; kz=kzLower+1;
11464 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11465 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLUU=-1;}
11466 int kLUU =2*kx + nx*ky+ nxny*kz ;
11472 kx= kxLower+1; ky =kyLower; kz=kzLower;
11476 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11477 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagULL=-1;}
11478 int kULL =2*kx + nx*ky+ nxny*kz ;
11484 kx= kxLower+1; ky =kyLower; kz=kzLower+1;
11488 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11489 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagULU=-1;}
11490 int kULU =2*kx + nx*ky+ nxny*kz ;
11496 kx= kxLower+1; ky =kyLower+1; kz=kzLower;
11500 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11501 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagUUL=-1;}
11502 int kUUL =2*kx + nx*ky+ nxny*kz ;
11508 kx= kxLower+1; ky =kyLower+1; kz=kzLower+1;
11512 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11513 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagUUU=-1;}
11514 int kUUU =2*kx + nx*ky+ nxny*kz ;
11530 src_data[kLLL] , src_data[kULL],
11531 src_data[kLUL] , src_data[kUUL],
11532 src_data[kLLU] , src_data[kULU],
11533 src_data[kLUU] , src_data[kUUU],
11534 dkxUpper,dkyUpper,dkzUpper);
11537 flagLLL*src_data[kLLL+1], flagULL*src_data[kULL+1],
11538 flagLUL*src_data[kLUL+1], flagUUL*src_data[kUUL+1],
11539 flagLLU*src_data[kLLU+1], flagULU*src_data[kULU+1],
11540 flagLUU*src_data[kLUU+1], flagUUU*src_data[kUUU+1],
11541 dkxUpper,dkyUpper,dkzUpper);
11544 float tempRb=tempR*Cphase - tempI*Sphase;
11545 float tempIb=tempR*Sphase + tempI*Cphase;
11547 des_data[IndexOut] = tempRb;
11548 des_data[IndexOut+1] = tempIb;
11551 if ((nz > 1)&&(image ->
is_real())) {
11552 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
11553 Vec3f offset(nx/2,ny/2,nz/2);
11554 float x2, y2, z2, tuvx, tuvy, tuvz;
11556 for (
int k = 0; k < nz; ++k) {
11557 for (
int j = 0; j < ny; ++j) {
11558 for (
int i = 0; i < nx; ++i,++l) {
11559 Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
11560 Vec3f soln = inv*coord;
11567 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) {
11577 ii = ix + iy * nx + iz * nxy;
11588 if (ix == nx - 1) {
11594 if (iy == ny - 1) {
11600 if (iz == nz - 1) {
11608 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
11609 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz);
11621 int ndim = image->get_ndim();
11622 if (ndim != 2 && ndim != 3)
throw ImageDimensionException(
"Transforming an EMData only works if it's 2D or 3D");
11680#ifdef EMAN2_USING_CUDA
11681 if(EMData::usecuda == 1 && image->isrodataongpu()){
11683 p =
new EMData(0,0,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
11684 float * m =
new float[12];
11687 image->bindcudaarrayA(
true);
11689 image->unbindcudaarryA();
11697 p =
new EMData(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize(),image->get_attr_dict());
11703 if (scale != 1.0) {
11704 p->scale_pixel(1.0f/scale);
11733 bool use_cpu =
true;
11735#ifdef EMAN2_USING_CUDA
11736 if(EMData::usecuda == 1 && image->isrodataongpu()){
11738 image->bindcudaarrayA(
false);
11739 float * m =
new float[12];
11743 image->unbindcudaarryA();
11751 image->set_data(des_data,image->get_xsize(),image->get_ysize(),image->get_zsize());
11755 if (scale != 1.0f) {
11756 image->scale_pixel(1.0f/scale);
11769 unsigned int dim =
static_cast<unsigned int> (image->get_ndim());
11771 if ( translation.size() != dim ) {
11772 for(
unsigned int i = translation.size(); i < dim; ++i ) translation.push_back(0);
11777 clip_region =
Region(-translation[0],image->get_xsize());
11778 }
else if ( dim == 2 ) {
11779 clip_region =
Region(-translation[0],-translation[1],image->get_xsize(),image->get_ysize());
11780 }
else if ( dim == 3 ) {
11781 clip_region =
Region(-translation[0],-translation[1],-translation[2],image->get_xsize(),image->get_ysize(),image->get_zsize());
11784 return clip_region;
11808 return image->
get_clip(clip_region,0);
11814 int ndim = image->get_ndim();
11817 if ( image->get_xsize() != image->get_ysize()) {
11818 throw ImageDimensionException(
"x size and y size of image do not match. This processor only works for uniformly sized data");
11821 if ( image->get_xsize() != image->get_zsize()) {
11822 throw ImageDimensionException(
"x size and z size of image do not match. This processor only works for uniformly sized data");
11838 clip = (int)(scale*image->get_xsize());
11843 r =
Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
11845 r =
Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
11854 image->process_inplace(
"xform",
Dict(
"transform",&t));
11855 }
else if (scale < 1) {
11858 image->process_inplace(
"xform",
Dict(
"transform",&t));
11881 memcpy(image->get_data(),tmp->get_data(),image->get_size()*
sizeof(
float));
11890 vector<float> centers;
11894 if (segbymerge) { segbymerge=nseg; nseg=4096; }
11896 EMData *ret=
new EMData(image->get_xsize(),image->get_ysize(),image->get_zsize());
11900 int nx=image->get_xsize();
11901 int ny=image->get_ysize();
11902 int nz=image->get_zsize();
11907 for (
int z=1; z<nz-1; z++) {
11908 for (
int y=1;
y<ny-1;
y++) {
11909 for (
int x=1;
x<nx-1;
x++) {
11910 if (image->get_value_at(
x,
y,z)>=thr) n2seg++;
11914 if (verbose) printf(
"%ld voxels above threshold\n",n2seg);
11917 vector<WSsortlist> srt(n2seg);
11919 for (
int z=1; z<nz-1; z++) {
11920 for (
int y=1;
y<ny-1;
y++) {
11921 for (
int x=1;
x<nx-1;
x++) {
11922 if (image->get_value_at(
x,
y,z)>=thr) {
11923 srt[i].pix=image->get_value_at(
x,
y,z);
11932 if (verbose) printf(
"Voxels extracted, sorting\n");
11935 sort(srt.begin(), srt.end());
11936 if (verbose) printf(
"Voxels sorted (%1.4g max), starting watershed\n",srt[0].pix);
11941 for (i=0; i<n2seg; i++) {
11946 for (
int zz=z-1; zz<=z+1; zz++) {
11947 for (
int yy=
y-1; yy<=
y+1; yy++) {
11948 for (
int xx=
x-1; xx<=
x+1; xx++) {
11949 float v=ret->get_value_at(xx,yy,zz);
11955 if (verbose) printf(
"%d %d %d\t%1.0f\t%1.3g\n",
x,
y,z,cseg,srt[i].pix);
11957 centers.push_back(
x);
11958 centers.push_back(
y);
11959 centers.push_back(z);
11964 if (verbose) printf(
"Requested number of segments achieved at density %1.4g\n",srt[i].pix);
11967 ret->set_value_at_fast(
x,
y,z,lvl);
11974 for (i=start; i<n2seg; i++) {
11978 if (ret->get_value_at(
x,
y,z)!=0)
continue;
11981 for (
int zz=z-1; zz<=z+1; zz++) {
11982 for (
int yy=
y-1; yy<=
y+1; yy++) {
11983 for (
int xx=
x-1; xx<=
x+1; xx++) {
11984 float v=ret->get_value_at(xx,yy,zz);
11989 if (lvl==0)
continue;
11990 ret->set_value_at_fast(
x,
y,z,lvl);
11993 if (verbose) printf(
"%ld voxels changed\n",chg);
11995 ret->set_attr(
"segment_centers",centers);
11998 if (cseg<segbymerge)
return ret;
12000 else if (cseg<=nseg)
return ret;
12002 if (verbose) printf(
"Merging segments\n");
12005 int nsegstart=(int)cseg;
12008 float *mxd=mx->get_data();
12011 int sub1=-1,sub2=-1;
12013 while (segbymerge<nseg) {
12016 for (i=0; i<n2seg; i++) {
12021 int v1=(int)ret->get_value_at(
x,
y,z);
12022 if (v1==sub2) { ret->set_value_at_fast(
x,
y,z,sub1); v1=sub1; }
12023 mxd[v1+v1*nsegstart]++;
12024 for (
int zz=z-1; zz<=z+1; zz++) {
12025 for (
int yy=
y-1; yy<=
y+1; yy++) {
12026 for (
int xx=
x-1; xx<=
x+1; xx++) {
12027 int v2=(int)ret->get_value_at(xx,yy,zz);
12028 if (v2==sub2) v2=sub1;
12029 if (v1==v2)
continue;
12030 mxd[v1+v2*nsegstart]+=image->get_value_at(xx,yy,zz);
12037 if (verbose && sub1==-1) { mx->write_image(
"contactmx.hdf",0); }
12046 for (
int s1=1; s1<nsegstart; s1++) {
12047 for (
int s2=1; s2<nsegstart; s2++) {
12048 if (s1==s2)
continue;
12049 float v=mxd[s1+s2*nsegstart];
12050 if (v==0)
continue;
12052 v/=max(mxd[s1+s1*nsegstart],mxd[s2+s2*nsegstart]);
12053 if (v>bestv) { bestv=v; sub1=s1; sub2=s2; }
12058 for (i=nsegstart+1; i<nsegstart*nsegstart; i+=nsegstart+1)
12059 if (mxd[i]>mv) { mv=mxd[i]; mvl=i/nsegstart; }
12060 if (verbose) printf(
"Merging %d to %d (%1.0f, %d)\n",sub2,sub1,mv,mvl);
12062 if (verbose) printf(
"Unable to find segments to merge, aborting\n");
12073 int ndim = image->get_ndim();
12076 if ( image->get_xsize() != image->get_ysize()) {
12077 throw ImageDimensionException(
"x size and y size of image do not match. This processor only works for uniformly sized data");
12080 if ( image->get_xsize() != image->get_zsize()) {
12081 throw ImageDimensionException(
"x size and z size of image do not match. This processor only works for uniformly sized data");
12097 clip = (int)(scale*image->get_xsize());
12102 r =
Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip);
12104 r =
Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip);
12115 ret->process_inplace(
"xform",
Dict(
"transform",&t));
12117 ret = image->process(
"xform",
Dict(
"transform",&t));
12119 }
else if (scale < 1) {
12122 ret = image->process(
"xform",
Dict(
"transform",&t));
12130 ret = image->copy();
12141 if (image->get_ndim() != 2) {
12145#ifdef EMAN2_USING_CUDA
12146 if (EMData::usecuda == 1 && image->getcudarwdata()) {
12148 emdata_rotate_180(image->getcudarwdata(), image->get_xsize(), image->get_ysize());
12154 float *d = image->get_data();
12155 int nx = image->get_xsize();
12156 int ny = image->get_ysize();
12160 if (nx % 2 == 1) x_offset=1;
12162 if (ny % 2 == 1) y_offset=1;
12165 for (
int x = 1;
x <= (nx/2+x_offset);
x++) {
12167 for (
y = 1;
y < (ny+y_offset);
y++) {
12168 if (
x == (nx / 2+x_offset) &&
y == (ny / 2+y_offset)) {
12172 int i = (
x-x_offset) + (
y-y_offset) * nx;
12173 int k = nx -
x + (ny -
y) * nx;
12189 if (x_offset == 0) {
12190 for (
int y = 0;
y < ny;
y++) {
12191 image->set_value_at_fast(0,
y,image->get_value_at(1,
y));
12195 if (y_offset == 0) {
12196 for (
int x = 0;
x < nx;
x++) {
12197 image->set_value_at_fast(
x,0,image->get_value_at(
x,1));
12201 if (y_offset == 0 && x_offset == 0) {
12202 image->set_value_at_fast(0,0,image->get_value_at(1,1));
12213 if ( image->is_complex() )
throw ImageFormatException(
"Error: clamping processor does not work on complex images");
12219 float new_min_vals = min;
12220 float new_max_vals = max;
12221 if (tomean) new_min_vals = new_max_vals = image->get_attr(
"mean");
12222 if (tozero) new_min_vals = new_max_vals = 0.0;
12228 size_t size = image->get_size();
12229 for(
size_t i = 0; i < size; ++i )
12231 float * data = &image->get_data()[i];
12232 if ( *data < min ) *data = new_min_vals;
12233 else if ( *data > max ) *data = new_max_vals;
12240 int startx = (int)region.
origin[0] - (
int)region.
size[0]/2;
12241 int starty = (int)region.
origin[1] - (
int)region.
size[1]/2;
12242 int startz = (int)region.
origin[2] - (
int)region.
size[2]/2;
12244 int endx = (int)region.
origin[0] + (
int)region.
size[0]/2;
12245 int endy = (int)region.
origin[1] + (
int)region.
size[1]/2;
12246 int endz = (int)region.
origin[2] + (
int)region.
size[2]/2;
12250 for (
float z = (
float)startz; z < (float)endz; z += 0.25f ) {
12251 for (
float y = (
float)starty;
y < (float)endy;
y += 0.25f ) {
12252 for (
float x = (
float)startx;
x < (float)endx;
x += 0.25f ) {
12253 xt = (float)
x - region.
origin[0];
12254 yt = (
float)
y - region.
origin[1];
12255 zt = (float) z - region.
origin[2];
12256 Vec3f v((
float)xt,(float)yt,(
float)zt);
12258 image->set_value_at((
int)(v[0]+region.
origin[0]),(
int)(v[1]+region.
origin[1]),(
int)(v[2]+region.
origin[2]), value);
12263 for (
int z = startz; z < endz; ++z ) {
12264 for (
int y = starty;
y < endy; ++
y ) {
12265 for (
int x = startx;
x < endx; ++
x ) {
12266 image->set_value_at(
x,
y,z, value);
12280 float nx = (float) image->get_xsize();
12281 float ny = (float) image->get_ysize();
12282 float nz = (float) image->get_zsize();
12287 float inc = 1.0f/22.0f;
12293 d[
"a"] = (float) .4*
nx+3;
12294 d[
"b"] = (float) .4*
ny+3;
12295 d[
"c"] = (float) .4*
nz+3;
12297 image->process_inplace(
"testimage.ellipsoid",d);
12299 d[
"a"] = (float) .4*
nx;
12300 d[
"b"] = (float) .4*
ny;
12301 d[
"c"] = (float) .4*
nz;
12303 image->process_inplace(
"testimage.ellipsoid",d);
12310 d[
"transform"] = &t;
12311 d[
"a"] = (float) 2.*xinc*
nx;
12312 d[
"b"] = (float)0.5*yinc*
ny;
12313 d[
"c"] = (float) 1.*zinc*
nz;
12315 image->process_inplace(
"testimage.ellipsoid",d);
12322 d[
"transform"] = &t;
12323 d[
"a"] = (float) 1.5*xinc*
nx;
12324 d[
"b"] = (float)0.5*yinc*
ny;
12325 d[
"c"] = (float) 1.*zinc*
nz;
12327 image->process_inplace(
"testimage.ellipsoid",d);
12333 d[
"transform"] = &t;
12334 d[
"a"] = (float) 1.*xinc*
nx;
12335 d[
"b"] = (float)0.5*yinc*
ny;
12336 d[
"c"] = (float) 1.*zinc*
nz;
12338 image->process_inplace(
"testimage.ellipsoid",d);
12346 d[
"transform"] = &t;
12347 d[
"a"] = (float) .75*xinc*
nx;
12348 d[
"b"] = (float)0.5*yinc*
ny;
12349 d[
"c"] = (float) 1.*zinc*
nz;
12351 image->process_inplace(
"testimage.ellipsoid",d);
12359 d[
"transform"] = &t;
12360 d[
"a"] = (float) 2*xinc*
nx;
12361 d[
"b"] = (float)0.5*yinc*
ny;
12362 d[
"c"] = (float) 1.*zinc*
nz;
12364 image->process_inplace(
"testimage.ellipsoid",d);
12371 d[
"transform"] = &t;
12372 d[
"a"] = (float) 1.5*xinc*
nx;
12373 d[
"b"] = (float)0.5*yinc*
ny;
12374 d[
"c"] = (float) 1.*zinc*
nz;
12376 image->process_inplace(
"testimage.ellipsoid",d);
12383 d[
"transform"] = &t;
12384 d[
"a"] = (float) 1*xinc*
nx;
12385 d[
"b"] = (float)0.5*yinc*
ny;
12386 d[
"c"] = (float) 1.*zinc*
nz;
12388 image->process_inplace(
"testimage.ellipsoid",d);
12395 d[
"transform"] = &t;
12396 d[
"a"] = (float).75*xinc*
nx;
12397 d[
"b"] = (float)0.5*yinc*
ny;
12398 d[
"c"] = (float) 1.*zinc*
nz;
12400 image->process_inplace(
"testimage.ellipsoid",d);
12409 d[
"transform"] = &t;
12410 d[
"a"] = (float)1*xinc*
nx;
12411 d[
"b"] = (float).75*yinc*
ny;
12412 d[
"c"] = (float) .75*zinc*
nz;
12414 image->process_inplace(
"testimage.ellipsoid",d);
12421 d[
"transform"] = &t;
12422 d[
"a"] = (float)1.5*xinc*
nx;
12423 d[
"b"] = (float).75*yinc*
ny;
12424 d[
"c"] = (float) .75*zinc*
nz;
12426 image->process_inplace(
"testimage.ellipsoid",d);
12433 d[
"transform"] = &t;
12434 d[
"a"] = (float)2*xinc*
nx;
12435 d[
"b"] = (float).75*yinc*
ny;
12436 d[
"c"] = (float) .75*zinc*
nz;
12438 image->process_inplace(
"testimage.ellipsoid",d);
12445 d[
"transform"] = &t;
12446 d[
"a"] = (float)2.5*xinc*
nx;
12447 d[
"b"] = (float).75*yinc*
ny;
12448 d[
"c"] = (float) 1*zinc*
nz;
12450 image->process_inplace(
"testimage.ellipsoid",d);
12457 d[
"transform"] = &t;
12458 d[
"a"] = (float) 3*xinc*
nx;
12459 d[
"b"] = (float).75*yinc*
ny;
12460 d[
"c"] = (float) 1*zinc*
nz;
12462 image->process_inplace(
"testimage.ellipsoid",d);
12499 rot[
"type"] =
"eman";
12503 d[
"transform"] = &t;
12504 d[
"a"] = (float) 1.5*xinc*
nx;
12505 d[
"b"] = (float) .5*yinc*
ny;
12506 d[
"c"] = (float) .5*zinc*
nz;
12508 image->process_inplace(
"testimage.ellipsoid",d);
12514 rot[
"type"] =
"eman";
12515 rot[
"az"] = 135.0f;
12518 d[
"transform"] = &t;
12519 d[
"a"] = (float) 1.5*xinc*
nx;
12520 d[
"b"] = (float) .5*yinc*
ny;
12521 d[
"c"] = (float) .5*zinc*
nz;
12523 image->process_inplace(
"testimage.ellipsoid",d);
12531 d[
"transform"] = &t;
12532 d[
"a"] = (float) .5*xinc*
nx;
12533 d[
"b"] = (float) .5*yinc*
ny;
12534 d[
"c"] = (float) .5*zinc*
nz;
12536 image->process_inplace(
"testimage.ellipsoid",d);
12539 image->process_inplace(
"testimage.ellipsoid",d);
12542 image->process_inplace(
"testimage.ellipsoid",d);
12545 image->process_inplace(
"testimage.ellipsoid",d);
12548 image->process_inplace(
"testimage.ellipsoid",d);
12569 d[
"transform"] = &t;
12570 d[
"a"] = (float) .5*xinc*
nx;
12571 d[
"b"] = (float) .5*yinc*
ny;
12572 d[
"c"] = (float) .5*zinc*
nz;
12574 image->process_inplace(
"testimage.ellipsoid",d);
12580 d[
"transform"] = &t;
12581 d[
"a"] = (float) .25*xinc*
nx;
12582 d[
"b"] = (float) .25*yinc*
ny;
12583 d[
"c"] = (float) .25*zinc*
nz;
12585 image->process_inplace(
"testimage.ellipsoid",d);
12588 image->process_inplace(
"testimage.ellipsoid",d);
12591 image->process_inplace(
"testimage.ellipsoid",d);
12594 image->process_inplace(
"testimage.ellipsoid",d);
12597 image->process_inplace(
"testimage.ellipsoid",d);
12600 image->process_inplace(
"testimage.ellipsoid",d);
12603 image->process_inplace(
"testimage.ellipsoid",d);
12606 image->process_inplace(
"testimage.ellipsoid",d);
12609 image->process_inplace(
"testimage.ellipsoid",d);
12612 image->process_inplace(
"testimage.ellipsoid",d);
12627 float sigma = image->get_attr(
"sigma");
12628 float mean = image->get_attr(
"mean");
12629 params.
put(
"minval",mean - nsigma*sigma);
12630 params.
put(
"maxval",mean + nsigma*sigma);
12637 float min = image->get_attr(
"minimum");
12638 float max = image->get_attr(
"maximum");
12642 vector<int> debugscores;
12644 debugscores = vector<int>((
int)nbins, 0);
12649 float bin_width = (max-min)/nbins;
12650 float bin_val_offset = bin_width/2.0f;
12652 size_t size = image->get_size();
12653 float* dat = image->get_data();
12655 for(
size_t i = 0; i < size; ++i ) {
12656 float val = dat[i];
12658 int bin = (int) (val/bin_width);
12661 if (bin == nbins) bin -= 1;
12663 dat[i] = min + bin*bin_width + bin_val_offset;
12665 debugscores[bin]++;
12671 for( vector<int>::const_iterator it = debugscores.begin(); it != debugscores.end(); ++it, ++i)
12672 cout <<
"Bin " << i <<
" has " << *it <<
" pixels in it" << endl;
12683 EMData* newimage = fourierproduct(image, with, CIRCULANT, CONVOLUTION,
false);
12685 float* orig = image->get_data();
12686 float* work = newimage->get_data();
12687 int nx = image->get_xsize();
12688 int ny = image->get_ysize();
12689 int nz = image->get_zsize();
12690 memcpy(orig,work,nx*ny*nz*
sizeof(
float));
12701 int nx = image->get_xsize();
12702 int ny = image->get_ysize();
12703 int nz = image->get_zsize();
12705 if ( nz == 1 && ny == 1 ) {
12706 if ( nx < 3 )
throw ImageDimensionException(
"Error - cannot edge detect an image with less than three pixels");
12708 e->set_size(3,1,1);
12709 e->set_value_at(0,-1);
12710 e->set_value_at(2, 1);
12714 }
else if ( nz == 1 ) {
12715 if ( nx < 3 || ny < 3 )
throw ImageDimensionException(
"Error - cannot edge detect an image with less than three pixels");
12716 e->set_size(3,3,1);
12717 e->set_value_at(0,0,-1);
12718 e->set_value_at(0,1,-2);
12719 e->set_value_at(0,2,-1);
12721 e->set_value_at(2,0,1);
12722 e->set_value_at(2,1,2);
12723 e->set_value_at(2,2,1);
12727 if ( nx < 3 || ny < 3 || nz < 3)
throw ImageDimensionException(
"Error - cannot edge detect an image with less than three pixels");
12728 e->set_size(3,3,3);
12729 e->set_value_at(0,0,0,-1);
12730 e->set_value_at(0,1,0,-1);
12731 e->set_value_at(0,2,0,-1);
12732 e->set_value_at(0,0,1,-1);
12733 e->set_value_at(0,1,1,-8);
12734 e->set_value_at(0,2,1,-1);
12735 e->set_value_at(0,0,2,-1);
12736 e->set_value_at(0,1,2,-1);
12737 e->set_value_at(0,2,2,-1);
12739 e->set_value_at(2,0,0,1);
12740 e->set_value_at(2,1,0,1);
12741 e->set_value_at(2,2,0,1);
12742 e->set_value_at(2,0,1,1);
12743 e->set_value_at(2,1,1,8);
12744 e->set_value_at(2,2,1,1);
12745 e->set_value_at(2,0,2,1);
12746 e->set_value_at(2,1,2,1);
12747 e->set_value_at(2,2,2,1);
12754 conv_parms[
"with"] = e;
12755 image->process_inplace(
"math.convolution", conv_parms);
12756 image->process_inplace(
"xform.phaseorigin.tocenter");
12767 alt = image->get_attr(
"euler_alt");
12771 float cosine = cos(alt*M_PI/180.0f);
12772 float mult_fac = 1.0f/(cosine);
12773 image->mult( mult_fac );
12781 if (biedgemean && edgemean)
throw InvalidParameterException(
"The edgemean and biedgemean options are mutually exclusive");
12788 alt = (float) d[
"alt"];
12789 if(t) {
delete t; t=0;}
12794 float cosine = cos(alt*M_PI/180.0f);
12797 int nx = image->get_xsize();
12798 int ny = image->get_ysize();
12799 int x_clip =
static_cast<int>( (float) nx * ( 1.0 - cosine ) / 2.0);
12801 float x1_edge_mean = 0.0;
12802 float x2_edge_mean = 0.0;
12806 float edge_mean = 0.0;
12809 for (
int i = 0; i < ny; ++i ) {
12810 edge_mean += image->get_value_at(x_clip, i );
12811 edge_mean += image->get_value_at(nx - x_clip-1, i );
12817 for (
int i = 0; i < ny; ++i ) {
12818 for (
int j = nx-1; j >= nx - x_clip; --j) {
12819 image->set_value_at(j,i,edge_mean);
12821 for (
int j = 0; j < x_clip; ++j) {
12822 image->set_value_at(j,i,edge_mean);
12825 x1_edge_mean = edge_mean;
12826 x2_edge_mean = edge_mean;
12830 for (
int i = 0; i < ny; ++i ) {
12831 x1_edge_mean += image->get_value_at(x_clip, i );
12832 x2_edge_mean += image->get_value_at(nx - x_clip-1, i );
12834 x1_edge_mean /= ny;
12835 x2_edge_mean /= ny;
12837 for (
int i = 0; i < ny; ++i ) {
12838 for (
int j = 0; j < x_clip; ++j) {
12839 image->set_value_at(j,i,x1_edge_mean);
12841 for (
int j = nx-1; j >= nx - x_clip; --j) {
12842 image->set_value_at(j,i,x2_edge_mean);
12850 zero_dict[
"x0"] = x_clip;
12851 zero_dict[
"x1"] = x_clip;
12852 zero_dict[
"y0"] = 0;
12853 zero_dict[
"y1"] = 0;
12854 image->process_inplace(
"mask.zeroedge2d", zero_dict );
12858 if ( gauss_rad != 0)
12863 if ( gauss_rad > x_clip ) gauss_rad = x_clip;
12867 float sigma = (float) gauss_rad/gauss_sigma;
12871 for (
int i = 0; i < ny; ++i ) {
12873 float left_value = image->get_value_at(x_clip, i );
12874 float scale1 = left_value-x1_edge_mean;
12876 float right_value = image->get_value_at(nx - x_clip - 1, i );
12877 float scale2 = right_value-x2_edge_mean;
12879 for (
int j = 1; j < gauss_rad; ++j )
12881 image->set_value_at(x_clip-j, i, scale1*gf((
float)j)+x1_edge_mean );
12882 image->set_value_at(nx - x_clip + j-1, i, scale2*gf((
float)j)+x2_edge_mean);
12895 int nx = image->get_xsize();
12896 int ny = image->get_ysize();
12897 int nz = image->get_zsize();
12899 if ( nz == 1 && ny == 1 ) {
12901 }
else if ( nz == 1 ) {
12902 if ( nx < 3 || ny < 3 )
throw ImageDimensionException(
"Error - cannot edge detect an image with less than three pixels");
12903 e->set_size(3,3,1);
12904 e->set_value_at(0,0,-1);
12905 e->set_value_at(1,0,-2);
12906 e->set_value_at(2,0,-1);
12908 e->set_value_at(0,2,1);
12909 e->set_value_at(1,2,2);
12910 e->set_value_at(2,2,1);
12914 if ( nx < 3 || ny < 3 || nz < 3)
throw ImageDimensionException(
"Error - cannot edge detect an image with less than three pixels");
12915 e->set_size(3,3,3);
12916 e->set_value_at(0,0,0,-1);
12917 e->set_value_at(1,0,0,-1);
12918 e->set_value_at(2,0,0,-1);
12919 e->set_value_at(0,0,1,-1);
12920 e->set_value_at(1,0,1,-8);
12921 e->set_value_at(2,0,1,-1);
12922 e->set_value_at(0,0,2,-1);
12923 e->set_value_at(1,0,2,-1);
12924 e->set_value_at(2,0,2,-1);
12926 e->set_value_at(0,2,0,1);
12927 e->set_value_at(1,2,0,1);
12928 e->set_value_at(2,2,0,1);
12929 e->set_value_at(0,2,1,1);
12930 e->set_value_at(1,2,1,8);
12931 e->set_value_at(2,2,1,1);
12932 e->set_value_at(0,2,2,1);
12933 e->set_value_at(1,2,2,1);
12934 e->set_value_at(2,2,2,1);
12941 conv_parms[
"with"] = e;
12942 image->process_inplace(
"math.convolution", conv_parms);
12943 image->process_inplace(
"xform.phaseorigin.tocenter");
12953 int nx = image->get_xsize();
12954 int ny = image->get_ysize();
12955 int nz = image->get_zsize();
12957 if ( nx < 3 || ny < 3 || nz < 3)
throw ImageDimensionException(
"Error - cannot edge detect in the z direction with any dimension being less than three pixels");
12959 e->set_size(3,3,3);
12960 e->set_value_at(0,0,0,-1);
12961 e->set_value_at(1,0,0,-1);
12962 e->set_value_at(2,0,0,-1);
12963 e->set_value_at(0,1,0,-1);
12964 e->set_value_at(1,1,0,-8);
12965 e->set_value_at(2,1,0,-1);
12966 e->set_value_at(0,2,0,-1);
12967 e->set_value_at(1,2,0,-1);
12968 e->set_value_at(2,2,0,-1);
12970 e->set_value_at(0,0,2,1);
12971 e->set_value_at(1,0,2,1);
12972 e->set_value_at(2,0,2,1);
12973 e->set_value_at(0,1,2,1);
12974 e->set_value_at(1,1,2,8);
12975 e->set_value_at(2,1,2,1);
12976 e->set_value_at(0,2,2,1);
12977 e->set_value_at(1,2,2,1);
12978 e->set_value_at(2,2,2,1);
12984 conv_parms[
"with"] = e;
12985 image->process_inplace(
"math.convolution", conv_parms);
12986 image->process_inplace(
"xform.phaseorigin.tocenter");
12994 d = image->process(
"math.edge.xgradient");
12995 image->process_inplace(
"math.edge.ygradient");
12997 image->process_inplace(
"normalize");
13004 image->process_inplace(
"math.edge.xgradient");
13005 image->process_inplace(
"math.squared");
13006 d = image->process(
"math.edge.ygradient");
13007 image->addsquare(*d);
13008 image->process_inplace(
"math.sqrt");
13015 int size = image->get_xsize() * image->get_ysize();
13016 image->process_inplace(
"math.edge.xgradient");
13017 d = image->process(
"math.edge.ygradient");
13018 for (
int i = 0; i < size; ++i ) {
13019 image->set_value_at_index(i,atan2(d->get_value_at_index(i),image->get_value_at_index(i)));
13027 image->process_inplace(
"math.edge.xgradient");
13028 image->process_inplace(
"math.edge.xgradient");
13029 image->process_inplace(
"math.squared");
13030 d = image->process(
"math.edge.ygradient");
13031 d->process_inplace(
"math.edge.ygradient");
13032 image->addsquare(*d);
13033 image->process_inplace(
"math.sqrt");
13040 int size = image->get_xsize() * image->get_ysize();
13041 image->process_inplace(
"math.edge.xgradient");
13042 image->process_inplace(
"math.edge.xgradient");
13043 image->process_inplace(
"math.squared");
13044 d = image->process(
"math.edge.ygradient");
13045 d->process_inplace(
"math.edge.ygradient");
13046 for (
int i = 0; i < size; ++i ) {
13047 image->set_value_at_index(i,atan2(d->get_value_at_index(i),image->get_value_at_index(i)));
13060 dx = image->process(
"math.edge.xgradient");
13061 dy = image->process(
"math.edge.ygradient");
13062 dxdx = dx->process(
"math.edge.xgradient");
13063 dxdy = dx->process(
"math.edge.ygradient");
13064 dydy = dy->process(
"math.edge.ygradient");
13077 dx->addsquare(*dy);
13088 dump_factory < Processor > ();
13093 return dump_factory_list < Processor > ();
13098 map<string, vector<string> > processor_groups;
13102 for (
size_t i = 0; i < processornames.size(); i++) {
13105 processor_groups[
"RealPixelProcessor"].push_back(f->
get_name());
13108 processor_groups[
"BoxStatProcessor"].push_back(f->
get_name());
13111 processor_groups[
"ComplexPixelProcessor"].push_back(f->
get_name());
13114 processor_groups[
"CoordinateProcessor"].push_back(f->
get_name());
13117 processor_groups[
"FourierProcessor"].push_back(f->
get_name());
13119 else if (
dynamic_cast<NewFourierProcessor*
>(f) != 0) {
13120 processor_groups[
"FourierProcessor"].push_back(f->
get_name());
13123 processor_groups[
"NormalizeProcessor"].push_back(f->
get_name());
13126 processor_groups[
"Others"].push_back(f->
get_name());
13130 return processor_groups;
13143 }
else if (type == 1) {
13145 ret = (1 - r * r / 4) * exp(-r * r / 4);
13146 }
else if (type == 2) {
13154 static float an[15] = { -3.9185246832229140e-16f,
13155 3.3957205298900993e-14f, 2.0343351971222658e-12f,
13156 -4.4935965816879751e-10f, 3.0668169835080933e-08f,
13157 -1.1904544689091790e-06f, 2.9753088549414953e-05f,
13158 -4.9802112876220150e-04f, 5.5900917825309360e-03f,
13159 -4.0823714462925299e-02f, 1.8021733669148599e-01f,
13160 -4.0992557296268717e-01f, 3.3980328566901458e-01f,
13161 -3.6062024812411908e-01f, 1.0000000000000000e+00f };
13164 for (
int i = 1; i < 15; i++) {
13165 ret = ret * r + an[i];
13177 int nx = cyl->get_xsize();
13178 int ny = cyl->get_ysize();
13179 int nz = cyl->get_zsize();
13188 if (x0 < 0 || x0 >= nx)
13190 if (y0 < 0 || y0 >= ny)
13192 if (z0 < 0 || z0 >= nz)
13195 float apix_x = cyl->get_attr(
"apix_x");
13196 float apix_y = cyl->get_attr(
"apix_y");
13197 float apix_z = cyl->get_attr(
"apix_z");
13199 float * dat = cyl->get_data();
13200 int cyl_voxel_len = (int) (len / apix_z);
13201 int cyl_k_min = z0 - cyl_voxel_len / 2;
13202 int cyl_k_max = z0 + cyl_voxel_len / 2;
13205 for (
int k = 0; k < nz; ++k) {
13206 for (
int j = 0; j < ny; ++j) {
13207 for (
int i = 0; i < nx; ++i, ++dat) {
13210 float radius = (float)hypot(
x * apix_x,
y * apix_y);
13211 if ((k > cyl_k_min) && (k < cyl_k_max))
13224 int nx = cyl->get_xsize();
13225 int ny = cyl->get_ysize();
13226 int nz = cyl->get_zsize();
13227 float apix_x = cyl->get_attr(
"apix_x");
13228 float apix_y = cyl->get_attr(
"apix_y");
13229 float apix_z = cyl->get_attr(
"apix_z");
13230 float lengthAngstroms =
params[
"length"];
13233 if (z0 < 0 || z0 >= nz)
13236 int z_start =
Util::round( z0 - 0.5*lengthAngstroms/apix_z );
13237 int z_stop =
Util::round( z0 + 0.5*lengthAngstroms/apix_z );
13239 float * dat = cyl->get_data();
13240 double rho_x_sum, rho_y_sum, rho_sum, x_cm, y_cm, radius;
13242 for (
int k = 0; k < nz; ++k)
13244 rho_x_sum = rho_y_sum = rho_sum = 0;
13246 if (k >= z_start && k <= z_stop)
13250 for (
int j = 0; j < ny; ++j)
13252 for (
int i = 0; i < nx; ++i, ++dat)
13254 rho_x_sum += (*dat)*i;
13255 rho_y_sum += (*dat)*j;
13262 x_cm = rho_x_sum/rho_sum;
13263 y_cm = rho_y_sum/rho_sum;
13266 for (
int j=0; j<ny;++j)
13268 for (
int i=0;i<nx;++i,++dat)
13270 radius = hypot( (i-x_cm)*apix_x, (j-y_cm)*apix_y );
13279 for (
int j=0; j<ny; j++)
13280 for(
int i=0; i<nx; i++)
13297 float threshold =
params[
"threshold"];
13301 Volume* vskel = VolumeSkeletonizer::PerformPureJuSkeletonization(vimage,
"unused",
static_cast<double>(threshold), min_curvew, min_srfcw);
13303 if (mark_surfaces) {
13304 VolumeSkeletonizer::MarkSurfaces(vskel);
13328 if (image->is_complex()) cimage = image->copy();
13329 else cimage = image->do_fft();
13330 cimage->process_inplace(
"xform.phaseorigin.tocorner");
13336 if (nky<4 || nky>=cimage->get_ysize()/2) nky=cimage->get_ysize()/8;
13337 if (nkx<5 || nky>=cimage->get_xsize()/2) nkx=cimage->get_xsize()/8+1;
13341 ret->set_complex(1);
13342 ret->set_fftpad(1);
13349 float dsbg=1.0/(float(image->get_attr(
"apix_x"))*image->get_xsize()*4.0);
13353 ret2->set_complex(1);
13355 ret2->set_fftpad(1);
13359 size_t laysize=nkx*2*nky*2;
13360 cimage=
new EMData((nkx+fp+2)*2,(nky+fp+2)*2,1);
13361 cimage->set_complex(1);
13363 cimage->set_fftpad(1);
13365 for (
int k=-cimage->get_ysize()/2; k<cimage->
get_ysize()/2; k++) {
13366 for (
int j=0; j<cimage->get_xsize()/2; j++) {
13367 cimage->set_complex_at(j,k,tmp->get_complex_at(j,k));
13373 for (
int k=2; k<2+fp; k++) {
13380 for (
float ang=0; ang<360.0; ang+=360.0/(nky*M_PI) ) {
13381 EMData *cimage2=cimage->process(
"xform",
Dict(
"alpha",ang));
13383 for (
int jy=-nky; jy<nky; jy++) {
13384 for (
int jx=0; jx<nkx; jx++) {
13385 if (jx==0 && jy<0)
continue;
13392 complex<double> v1 = (complex<double>)cimage2->get_complex_at(jx,jy);
13393 complex<double> v2 = (complex<double>)cimage2->get_complex_at(kx,ky);
13394 complex<double> v3 = (complex<double>)cimage2->get_complex_at(jkx,jky);
13395 ret->add_complex_at(jx,jy,0,(complex<float>)(v1*v2*std::conj(v3)));
13407 for (
int jy=-2; jy<=2; jy++) {
13408 for (
int jx=0; jx<=2; jx++) {
13409 ret->set_complex_at(jx,jy,0.0f);
13412 memcpy(ret2->get_data()+laysize*(k-2),ret->get_data(),laysize*
sizeof(
float));
13416 ret2->set_attr(
"dsbg",dsbg);
13430 cimage=
new EMData((nkx*2+fp)*2-2,(nky*2+fp)*2,1);
13431 cimage->set_complex(1);
13433 cimage->set_fftpad(1);
13434 int step=int(floor(tmp->get_ysize()/(2.0f*cimage->get_ysize())));
13436 if (step==0) step=1;
13439 for (
int k=-cimage->get_ysize()/2; k<cimage->
get_ysize()/2; k++) {
13440 for (
int j=0; j<cimage->get_xsize()/2; j++) {
13441 cimage->set_complex_at(j,k,tmp->get_complex_at(j*step,k*step));
13448 for (
int dk=0; dk<fp; dk++) {
13455 for (
float ang=0; ang<360.0; ang+=360.0/(nky*M_PI) ) {
13456 EMData *cimage2=cimage->process(
"xform",
Dict(
"alpha",ang,
"zerocorners",1));
13458 for (
int jy=-nky; jy<nky; jy++) {
13459 for (
int jx=0; jx<nkx; jx++) {
13460 if ((jx==0 && jy<0) || (jx+dk<4))
continue;
13472 complex<double> v1 = (complex<double>)cimage2->get_complex_at(jx,jy);
13473 complex<double> v2 = (complex<double>)cimage2->get_complex_at(kx,ky);
13474 complex<double> v3 = (complex<double>)cimage2->get_complex_at(jkx,jky);
13476 ret->add_complex_at(jx,jy,0,(complex<float>)(v1*v2*std::conj(v3)));
13505 for (
int x=0;
x<nkx-1;
x++) {
13506 for (
int y=-nky;
y<nky;
y++) {
13507 complex<float> val=ret->get_complex_at(
x,
y);
13509 ret2->set_value_at(
x,
y+nky+nky*dk*2,cbrt(
std::real(val)));
13517 ret2->set_attr(
"is_bispec_fp",(
int)fp);
13526 int rsize=cimage->get_ysize()/4-minr-2;
13527 if (rsize>nky) rsize=nky;
13533 line->set_complex(1);
13535 line->set_fftpad(1);
13537 for (
int angi=0; angi<nang; angi++) {
13538 float ofs=M_PI/float(nang);
13539 float dx=cos(2.0*M_PI*angi/
float(nang)+ofs);
13540 float dy=sin(2.0*M_PI*angi/
float(nang)+ofs);
13560 for (
int dr=0; dr<rfp; dr++) {
13562 for (
int r=minr; r<rsize+minr; r++) {
13565 float kx=dx*(r+dr);
13566 float ky=dy*(r+dr);
13569 complex<double> v1 = (complex<double>)cimage->get_complex_at_interp(jx,jy);
13570 complex<double> v2 = (complex<double>)cimage->get_complex_at_interp(kx,ky);
13571 complex<double> v3 = (complex<double>)cimage->get_complex_at_interp(jx+kx,jy+ky);
13572 complex<double> bv = v1*v2*std::conj(v3);
13573 line->set_complex_at(r,0,0,complex<float>(bv));
13574 lsq+=std::norm(bv);
13576 float rsig = 1.0/
sqrt(lsq/
double(rsize));
13595 for (
int i=0; i<rsize*2; i++) ret2->set_value_at(angi,i+dr*rsize*2,line->get_value_at(i+minr*2,0)*rsig);
13620 ret2->set_attr(
"is_bispec_rfp",(
int)rfp);
13631 for (
float ang=0; ang<360.0; ang+=360.0/(nky*M_PI) ) {
13633 EMData *cimage2=cimage->process(
"xform",
Dict(
"alpha",ang));
13635 for (
int jy=-nky; jy<nky; jy++) {
13636 for (
int jx=0; jx<nkx; jx++) {
13643 complex<double> v1 = (complex<double>)cimage2->get_complex_at(jx,jy);
13644 complex<double> v2 = (complex<double>)cimage2->get_complex_at(kx,ky);
13645 complex<double> v3 = (complex<double>)cimage2->get_complex_at(jkx,jky);
13646 ret->add_complex_at(jx,jy,0,(complex<float>)(v1*v2*std::conj(v3)));
13654 if (image->is_complex()) cimage = image->copy();
13655 else cimage = image->do_fft();
13656 cimage->process_inplace(
"xform.phaseorigin.tocorner");
13662 printf(
"nky = %d , size= %d \n",nky,image->get_xsize());
13678 ret->set_complex(0);
13689 for (
float ang=0; ang<360.0; ang+=2 ) {
13690 EMData *cimage2=cimage->process(
"xform",
Dict(
"alpha",ang));
13692 for (
int qy=-nky; qy<nky; qy++) {
13693 for (
int qx=-nkx; qx<nkx; qx++) {
13698 if (abs(kqx)>nkx || abs(kqy)>nky)
continue;
13701 complex<double> v1 = (complex<double>)cimage2->get_complex_at(kx,ky);
13702 complex<double> v2 = (complex<double>)cimage2->get_complex_at(qx,qy);
13703 complex<double> v3 = (complex<double>)cimage2->get_complex_at(kqx,kqy);
13704 complex<double> vTotal = (complex<double>)(v1*v2*std::conj(v3));
13705 double RealV = (
real)(vTotal);
13706 int jxInd = (qx+2*nkx)%(2*nkx);
13707 int jyInd = (qy+2*nky)%(2*nky);
13709 double OldVal = ret->get_value_at(jxInd,jyInd,0);
13710 ret->set_value_at(jxInd,jyInd,0,OldVal+RealV);
13720 if (image->is_complex()) cimage = image->copy();
13721 else cimage = image->do_fft();
13722 cimage->process_inplace(
"xform.phaseorigin.tocorner");
13731 printf(
"nkx = %d, nky = %d , size= %d \n",nkx,nky,image->get_xsize());
13735 ret->set_complex(0);
13741 for (
float ang=0; ang<360.0; ang+=2 ) {
13742 EMData *cimage2=cimage->process(
"xform",
Dict(
"alpha",ang));
13744 for (
int qy=-k; qy<k+1; qy++) {
13745 if (qy*qy> (0.75)*k*k)
continue;
13746 for (
int qx=-k; qx<1; qx++) {
13747 if ((qx+k)*(qx+k) > (k*k - qy*qy))
continue;
13750 complex<double> v1 = (complex<double>)cimage2->get_complex_at(kx,ky);
13751 complex<double> v2 = (complex<double>)cimage2->get_complex_at(qx,qy);
13752 complex<double> v3 = (complex<double>)cimage2->get_complex_at(kqx,kqy);
13753 complex<double> vTotal = (complex<double>)(v1*v2*std::conj(v3));
13754 double RealV = (
real)(vTotal);
13755 int qxInd = (qx+nkx)%(nkx);
13756 int qyInd = (qy+nky)%(nky);
13757 int NegQx = k/2 +qx ;
13758 int QyInd = qy+Nyquist;
13762 double OldVal = ret->get_value_at(NegQx,QyInd,0);
13764 ret->set_value_at(NegQx,QyInd,0,OldVal+RealV);
13778 if (image->is_complex()) cimage = image->copy();
13779 else cimage = image->do_fft();
13781 cimage->process_inplace(
"xform.phaseorigin.tocorner");
13788 int csizex = cimage->get_xsize();
13789 int csizey = cimage->get_ysize();
13791 printf(
"csizex = %d, csizey = %d \n", csizex , csizey );
13793 Nyquist = (csizey+1)/2;
13795 printf(
"csizex = %d, csizey = %d, Nyquist= %d \n", csizex , csizey, Nyquist);
13797 int nkx= Nyquist/2+1;
13798 int nky= 2*Nyquist+2;
13799 int nkz= Nyquist+1;
13802 printf(
"nkx = %d, nky = %d , size= %d \n",nkx,nky,image->get_xsize());
13807 ret->set_complex(0);
13812 for (
float ang=0; ang<360.0; ang+=2 ) {
13813 EMData *cimage2=cimage->process(
"xform",
Dict(
"alpha",ang));
13815 for (
int k=0; k < Nyquist+1;k++){
13818 int qyMax =
sqrt(3*k2/4);
13820 for (
int qy=-qyMax; qy<qyMax+1; qy++) {
13822 int qxMin =k/2; qxMin *= -1;
13823 int qxMax = k -
sqrt(k2-qy*qy)+0.999999; qxMax *= -1;
13824 for (
int qx=qxMin; qx<qxMax+1; qx++) {
13829 complex<double> v1 = (complex<double>)cimage2->get_complex_at(k,0);
13830 complex<double> v2 = (complex<double>)cimage2->get_complex_at(qx,qy);
13831 complex<double> v3 = (complex<double>)cimage2->get_complex_at(kqx,kqy);
13832 complex<double> vTotal = (complex<double>)(v1*v2*std::conj(v3));
13833 double RealV = (
real)(vTotal);
13834 int qxInd = (qx+nkx)%(nkx);
13835 int qyInd = (qy+nky)%(nky);
13836 int NegQx = k/2 +qx ;
13837 int QyInd = qy+Nyquist;
13840 double OldVal = ret->get_value_at(NegQx,QyInd,k);
13842 ret->set_value_at(NegQx,QyInd,k,OldVal+RealV);
13855 for (
int jy=-nky; jy<nky; jy++) {
13856 for (
int jx=0; jx<nkx; jx++) {
13861 complex<double> v1 = (complex<double>)cimage->get_complex_at(jx,jy);
13862 complex<double> v2 = (complex<double>)cimage->get_complex_at(kx,ky);
13863 complex<double> v3 = (complex<double>)cimage->get_complex_at(jkx,jky);
13864 ret->set_complex_at(jx,jy,(complex<float>)(v1*v2*std::conj(v3)));
13876 for (
int jy=-nky; jy<nky; jy++) {
13877 for (
int jx=0; jx<nkx; jx++) {
13879 complex<double> v1 = (complex<double>)cimage->get_complex_at(jx,jy);
13880 complex<double> v2 = (complex<double>)cimage->get_complex_at(kx,ky);
13881 complex<double> v3 = (complex<double>)cimage->get_complex_at(jx+kx,jy+ky);
13882 ret->set_complex_at(jx,jy,(complex<float>)(v1*v2*std::conj(v3)));
13888 for (
int jy=-nky; jy<nky; jy++) {
13889 ret->set_complex_at(0,jy,ret->get_complex_at(0,jy)/
sqrt(2.0f));
13890 ret->set_complex_at(nkx-1,jy,ret->get_complex_at(nkx-1,jy)/
sqrt(2.0f));
13899 if (image->get_zsize()!=1 || image->is_complex())
throw ImageDimensionException(
"Only 2-D real images supported");
13904 int s1=image->get_ysize();
13906 cimage=im2->do_fft();
13908 cimage->process_inplace(
"xform.phaseorigin.tocorner");
13912 int ny=cimage->get_ysize()/8;
13918 trns->set_complex(1);
13920 trns->set_fftpad(1);
13921 size_t xyz=trns->get_size();
13930 complex<float> *tmp = (complex<float>*)EMfft::fftmalloc(naz*2);
13931 for (
int jy=0; jy<ny/4; jy+=2) {
13932 for (
int x=0;
x<naz;
x++) trns->set_complex_at_idx(
x,jy,0,(complex<float>)std::polar((
float)sin(1.0f+jy/2.0f*
x*M_PI*2.0f/naz),-hn/100.0f));
13933 memcpy((
void*)tmp,(
void*)(trns->get_data()+jy*naz*2),naz*2*
sizeof(
float));
13934 EMfft::complex_to_complex_1d_inplace(tmp,naz*2);
13935 memcpy((
void*)(trns->get_data()+(jy+1)*naz*2),(
void*)tmp,naz*2*
sizeof(
float));
13937 EMfft::fftfree((
float *)tmp);
13954 for (
int ja=0; ja<naz; ja++) {
13955 float si=sin(
float(2.0*M_PI*(ja+0.5)/naz));
13956 float co=cos(
float(2.0*M_PI*(ja+0.5)/naz));
13957 for (
int jr=3; jr<ny/2 && jr*hn<ny*2; jr++) {
13960 complex<double> v2 = (complex<double>)cimage->get_complex_at_interp(jx,jy);
13961 complex<double> v1 = (complex<double>)cimage->get_complex_at_interp(jx*hn,jy*hn);
13966 trns->set_complex_at_idx(ja,jr,0,(complex<float>)(v1*std::pow(std::conj(v2),(
float)hn)));
13972 for (
size_t i=0; i<xyz; i+=2) {
13973 trns->set_value_at_index(i,pow(trns->get_value_at_index(i),float(1.0/(hn+1))));
13979 complex<float> *tmp = (complex<float>*)EMfft::fftmalloc(naz*2);
13980 for (
int jy=3; jy<ny/2; jy++) {
13981 memcpy((
void*)tmp,(
void*)(trns->get_data()+jy*naz*2),naz*2*
sizeof(
float));
13982 EMfft::complex_to_complex_1d_inplace(tmp,naz*2);
13983 memcpy((
void*)(trns->get_data()+jy*naz*2),(
void*)tmp,naz*2*
sizeof(
float));
13985 EMfft::fftfree((
float *)tmp);
13989 complex<float> *tmp = (complex<float>*)EMfft::fftmalloc(naz*2);
13990 for (
int jy=3; jy<ny/2; jy++) {
13993 memcpy((
void*)tmp,(
void*)(trns->get_data()+jy*naz*2),naz*2*
sizeof(
float));
13994 EMfft::complex_to_complex_1d_inplace(tmp,naz*2);
13995 for (
int jx=0; jx<naz; jx++) {
14001 trns->set_complex_at_idx(jx,jy,0,0.0f);
14004 complex<float> v2 = tmp[jx];
14005 complex<float> v1 = tmp[jx*rn];
14006 trns->set_complex_at_idx(jx,jy,0,v1*std::pow(std::conj(v2),(
float)rn));
14010 EMfft::fftfree((
float *)tmp);
14014 for (
size_t i=0; i<xyz; i+=2) {
14015 trns->set_value_at_index(i,pow(trns->get_value_at_index(i),
float(1.0/(rn+1))));
14019 trns->set_attr(
"is_harmonic_rn",(
int)rn);
14023 trns->set_size(ny,ny,1);
14024 xyz=trns->get_size();
14026 for (
int jx=0; jx<ny/2 && jx*hn<ny*2; jx++) {
14027 for (
int jy=max(-ny/2,-ny*2/hn); jy<ny/2 && jy*hn<ny*2; jy++) {
14029 trns->set_complex_at(jx,jy,0,(complex<float>)0);
14032 complex<double> v2 = (complex<double>)cimage->get_complex_at(jx,jy);
14033 complex<double> v1 = (complex<double>)cimage->get_complex_at(jx*hn,jy*hn);
14034 trns->set_complex_at(jx,jy,0,(complex<float>)(v1*std::pow(std::conj(v2),(
float)hn)));
14039 for (
size_t i=0; i<xyz; i+=2) {
14040 trns->set_value_at_index(i,pow(trns->get_value_at_index(i),float(1.0/(hn+1))));
14046 trns->set_attr(
"is_harmonic_hn",(
int)hn);
14052 for (
int ja=0; ja<naz; ja++) {
14053 float si=sin(
float(2.0*M_PI*(ja+0.5)/naz));
14054 float co=cos(
float(2.0*M_PI*(ja+0.5)/naz));
14058 for (
int jr=5; jr<ny/4; jr++) {
14060 for (
int hn=2; hn<=rfp; hn++) {
14063 complex<double> v2 = (complex<double>)cimage->get_complex_at_interp(jx,jy);
14064 complex<double> v1 = (complex<double>)cimage->get_complex_at_interp(jx*hn,jy*hn);
14065 v1*=std::pow(std::conj(v2),(
double)hn);
14066 v1=std::polar(std::pow(std::abs(v1),1.0/(hn+1.0))/ny,std::arg(v1));
14067 trns->set_complex_at_idx(ja,
y,0,(complex<float>)v1);
14069 if (
y>=ny/2)
break;
14071 if (
y>=ny/2)
break;
14076 trns->set_attr(
"is_harmonic_rfp",(
int)rfp);
14086 for (
int ja=0; ja<naz; ja++) {
14087 float si=sin(
float(2.0*M_PI*(ja+0.5)/naz));
14088 float co=cos(
float(2.0*M_PI*(ja+0.5)/naz));
14092 for (
int jr=3; jr<ny/4; jr++) {
14094 for (
int hn=2; hn<=fp; hn++) {
14097 complex<double> v2 = (complex<double>)cimage->get_complex_at_interp(jx,jy);
14098 complex<double> v1 = (complex<double>)cimage->get_complex_at_interp(jx*hn,jy*hn);
14099 v1*=std::pow(std::conj(v2),(
double)hn);
14100 v1=std::polar(std::pow(std::abs(v1),1.0/(hn+1.0))/ny,std::arg(v1));
14101 trns->set_complex_at_idx(ja,
y,0,(complex<float>)v1);
14103 if (
y>=ny/2)
break;
14105 if (
y>=ny/2)
break;
14111 complex<float> *tmp = (complex<float>*)EMfft::fftmalloc(naz*2);
14113 for (
int jy=0; jy<ny/2; jy++) {
14115 memcpy((
void*)tmp,(
void*)(trns->get_data()+jy*naz*2),naz*2*
sizeof(
float));
14116 EMfft::complex_to_complex_1d_inplace(tmp,naz*2);
14119 for (
int jx=1; jx<naz/2; jx++) {
14121 complex<double> v2 = tmp[jx];
14122 for (
int rn=2; rn<=fp; rn++) {
14123 if (jx*rn>=naz)
break;
14124 complex<double> v1 = tmp[jx*rn];
14125 v1*=std::pow(std::conj(v2),(
double)rn);
14126 v1=std::polar(std::pow(std::abs(v1),1.0/(rn+1.0))/naz,std::arg(v1));
14127 trns->set_complex_at_idx(
x,jy,0,(complex<float>)v1);
14129 if (
x>=naz/2)
break;
14131 if (
x>=naz/2)
break;
14134 EMfft::fftfree((
float *)tmp);
14142 ret->set_attr(
"is_harmonic_fp",(
int)fp);
14143 ret->set_complex(0);
14153 int nx = image->get_xsize();
14154 int ny = image->get_ysize();
14156 EMData* conv =
new EMData(image->get_xsize(),image->get_ysize(),1);
14159 vector<float> kernel;
14160 kernel =
params[
"kernel"];
14161 ks = int(
sqrt(
float(kernel.size())));
14164 float* data = image->get_data();
14165 float* cdata = conv->get_data();
14168 int n = (ks - 1)/2;
14169 for (
int i = n; i < (nx - n); i++) {
14170 for (
int j = n; j < (ny - n); j++) {
14175 for (
int cx = -n; cx <= n; cx++) {
14176 for (
int cy = -n; cy <= n; cy++, idx++) {
14177 cpixel += data[(i+cx)+(j+cy)*nx]*kernel[idx];
14180 cdata[i + j * nx] = cpixel;
14225 int x_size = image->get_xsize();
14226 int y_size = image->get_ysize();
int y_odd= (y_size%2);
14227 int z_size = image->get_zsize();
14231 int size_check = abs(x_size-y_size-2+y_odd)+ abs(z_size-1)*abs(z_size-y_size);
14232 int N = x_size/2-1;
14238 if (debug) printf(
"Mid=%d, x_size=%d, y_size=%d, N=%d, z_size=%d \n", Mid,x_size,y_size, N, z_size );
14241 EMData* WeightIm = image ->
copy(); WeightIm ->to_zero();
14242 EMData* PhaseOrigIm =
new EMData(N+1,2*N+1,z_size) ; PhaseOrigIm ->to_zero();
14243 EMData* PhaseFinalIm = PhaseOrigIm ->
copy(); PhaseFinalIm ->to_zero();
14244 EMData* MagFinalIm = PhaseOrigIm ->
copy(); MagFinalIm ->to_zero();
14250 float WeightNowX, WeightNowY, WeightNowZ ;
14251 int kxMin,kxMax, kyMin, kyMax, kzMin, kzMax, kxBefore, kyBefore, kzBefore ;
14252 float kxRT, kyRT, kzRT ;
14261 if (debug) {image ->
write_image(
"OrigImageFFT.hdf");
14262 printf(
"Just wrote OrigImageFFT.hdf \n"); }
14265 for (kxBefore = 0; kxBefore <= N ; ++kxBefore) {
14266 for (kyBefore = 0; kyBefore < y_size ; ++kyBefore) {
14267 for (kzBefore = 0; kzBefore < z_size ; ++kzBefore) {
14270 float CurrentReal = RotIm ->
get_value_at(2*kxBefore ,kyBefore, kzBefore);
14271 float CurrentImag = RotIm ->
get_value_at(2*kxBefore+1,kyBefore, kzBefore);
14276 float Phase = -pi*(kxBefore+kyBefore + kzBefore)*x_size/y_size;
14278 float CosPhase = cos( Phase);
14279 float SinPhase = sin( Phase);
14281 float NewRealValue = CosPhase*CurrentReal -SinPhase*CurrentImag;
14282 float NewImagValue = SinPhase*CurrentReal +CosPhase*CurrentImag;
14284 RotIm ->set_value_at(2*kxBefore ,kyBefore, kzBefore, NewRealValue);
14285 RotIm ->set_value_at(2*kxBefore+1,kyBefore, kzBefore, NewImagValue);
14288 if (debug) {RotIm ->
write_image(
"OrigImageFFTAfterPhaseCorrection.hdf");
14289 printf(
" Just wrote OrigImageFFTAfterPhaseCorrection.hdf \n");}
14292 if (debug) printf(
" Just about to start second loop \n");
14295 invRotNow = rotNow ->
inverse();
14298 for (
int kxAfter = 0; kxAfter <= N ; ++kxAfter) {
14299 for (
int kyAfter = -N; kyAfter < y_size-N ; ++kyAfter) {
14300 for (
int kzAfter = -z_size/2; kzAfter <= z_size/2 ; ++kzAfter) {
14304 PosAfter =
Vec3f(kxAfter, kyAfter, kzAfter);
14305 PosBefore = invRotNow*PosAfter;
14306 kxRT = PosBefore[0];
14307 kyRT = PosBefore[1];
14308 kzRT = PosBefore[2];
14311 kxMin = ceil( kxRT-interpCutoff); kxMax = floor(kxRT+interpCutoff);
14312 kyMin = ceil( kyRT-interpCutoff); kyMax = floor(kyRT+interpCutoff);
14313 kzMin = ceil( kzRT-interpCutoff); kzMax = floor(kzRT+interpCutoff);
14318 for (
int kxI= kxMin; kxI <= kxMax; ++kxI){
14319 for (
int kyI= kyMin; kyI <= kyMax; ++kyI){
14320 for (
int kzI= kzMin; kzI <= kzMax; ++kzI){
14323 if (abs(kxI) >N)
continue;
14324 if (abs(kyI) >N)
continue;
14325 if (abs(kzI) >z_size/2)
continue;
14327 float distx= abs(kxI-kxRT);
14328 float disty= abs(kyI-kyRT);
14329 float distz= abs(kzI-kzRT);
14332 int IsComplexConj= 1;
14334 if (kxI<0) IsComplexConj=-1;
14335 kxBefore= IsComplexConj*kxI;
14336 kyBefore= IsComplexConj*kyI;
14337 kzBefore= IsComplexConj*kzI;
14339 if ( kyBefore<0 ) kyBefore += y_size;
14340 if ( kzBefore<0 ) kzBefore += y_size;
14342 WeightNowX = (distx ==0)? 1: (sin(pi*distx) /(pi*distx)) ;
14343 WeightNowY = (disty ==0)? 1: (sin(pi*disty) /(pi*disty)) ;
14344 WeightNowZ = (distz ==0)? 1: (sin(pi*distz) /(pi*distz)) ;
14347 float CurrentValue;
14349 int kyAfterInd = (kyAfter+y_size)%(y_size);
14350 int kzAfterInd = (kzAfter+z_size)%(z_size);
14358 CurrentValue = image ->
get_value_at(2*kxAfter,kyAfterInd, kzAfterInd);
14359 ToAdd = WeightNowX*WeightNowY*WeightNowZ*(RotIm ->
get_value_at(2*kxBefore,kyBefore, kzBefore));
14360 image ->
set_value_at(2*kxAfter ,kyAfterInd , kzAfterInd, ToAdd + CurrentValue );
14363 CurrentValue = WeightIm ->
get_value_at(kxAfter,kyAfterInd, kzAfterInd);
14364 ToAdd = WeightNowX*WeightNowY;
14365 WeightIm ->
set_value_at(kxAfter , kyAfterInd , kzAfterInd, abs(ToAdd) + CurrentValue );
14367 CurrentValue = image ->
get_value_at(2*kxAfter+1,kyAfterInd);
14368 ToAdd = IsComplexConj*WeightNowX*WeightNowY*RotIm ->
get_value_at(2*kxBefore+1,kyBefore, kzBefore );
14369 image ->
set_value_at(2*kxAfter+1 , kyAfterInd , kzAfterInd, ToAdd + CurrentValue );
14380 if (debug) { image ->
write_image(
"RotImageBeforeFinalPhaseCorrection.hdf");
14381 printf(
" Just wrote RotImageBeforeFinalPhaseCorrection.hdf \n"); }
14384 for (kxBefore = 0; kxBefore <= N ; ++kxBefore) {
14385 for (kyBefore = 0; kyBefore < y_size ; ++kyBefore) {
14386 for (kzBefore = 0; kzBefore < z_size ; ++kzBefore) {
14388 float CurrentReal = image ->
get_value_at(2*kxBefore , kyBefore, kzBefore);
14389 float CurrentImag = image ->
get_value_at(2*kxBefore+1 , kyBefore, kzBefore);
14391 PhaseFinalIm ->
set_value_at(kxBefore,kyBefore, kzBefore, atan2(CurrentImag,CurrentReal));
14392 MagFinalIm ->
set_value_at(kxBefore,kyBefore, kzBefore,
sqrt(CurrentImag*CurrentImag+CurrentReal*CurrentReal) );
14393 float WeightNow = WeightIm ->
get_value_at(kxBefore,kyBefore, kzBefore);
14395 float val = (image->get_value_at(2*kxBefore , kyBefore, kzBefore))/WeightNow;
14396 image ->
set_value_at(2*kxBefore , kyBefore, kzBefore, val);
14397 val = (image->get_value_at(2*kxBefore +1 , kyBefore, kzBefore))/WeightNow;
14398 image ->
set_value_at(2*kxBefore +1 , kyBefore, kzBefore, val);
14403 if (debug) { printf(
" Just did normalization step \n");}
14406 for ( kxBefore = 0; kxBefore < Mid ; ++kxBefore) {
14407 for ( kyBefore = 0; kyBefore < y_size ; ++kyBefore) {
14408 for ( kzBefore = 0; kzBefore < z_size ; ++kzBefore) {
14410 float CurrentReal = image ->
get_value_at(2*kxBefore ,kyBefore, kzBefore);
14411 float CurrentImag = image ->
get_value_at(2*kxBefore+1,kyBefore, kzBefore);
14414 float Phase = pi*(kxBefore + kyBefore + kzBefore)*x_size/y_size;
14416 float CosPhase = cos( Phase);
14417 float SinPhase = sin( Phase);
14419 float NewRealValue = CosPhase*CurrentReal -SinPhase*CurrentImag;
14420 float NewImagValue = SinPhase*CurrentReal +CosPhase*CurrentImag;
14422 image ->set_value_at(2*kxBefore, kyBefore, kzBefore, NewRealValue);
14423 image ->set_value_at(2*kxBefore+1,kyBefore, kzBefore, NewImagValue);
14431 printf(
" Just wrote RotatedImageFFT.hdf \n");
14443 int x_size = image->get_xsize();
14444 int y_size = image->get_ysize();
14445 int z_size = image->get_zsize();
14447 int ix,iy,iz,it,count,ic;
14448 int *dx=
new int[thr*8],*dy=
new int[thr*8];
14449 for (it=1; it<=thr; it++){
14452 for (ix=-thr-1; ix<=thr+1; ix++){
14453 for (iy=-thr-1; iy<=thr+1; iy++){
14454 int d2=ix*ix+iy*iy;
14455 if (d2>=it*it && d2<(it+1)*(it+1)){
14463 for (iz=0; iz<z_size; iz++){
14464 for (ix=0; ix<x_size; ix++){
14465 for (iy=0; iy<y_size; iy++){
14468 if (bwmap->get_value_at(ix,iy,iz)==0)
14470 for (ic=0; ic<count; ic++){
14471 mn+=image->sget_value_at(ix+dx[ic],iy+dy[ic],iz);
14474 if (mn>bwmap->get_value_at(ix,iy,iz))
14476 bwmap->set_value_at(ix,iy,iz,mn);
14482 for (iz=0; iz<z_size; iz++){
14483 for (ix=0; ix<x_size; ix++){
14484 for (iy=0; iy<y_size; iy++){
14485 if (bwmap->get_value_at(ix,iy,iz)>0)
14486 bwmap->set_value_at(ix,iy,iz,1);
14488 bwmap->set_value_at(ix,iy,iz,0);
14501 memcpy(image->get_data(),tmp->get_data(),(
size_t)image->get_xsize()*image->get_ysize()*image->get_zsize()*
sizeof(
float));
14519 int nx = image->get_xsize();
14520 int ny = image->get_ysize();
14521 int nz = image->get_zsize();
14526 EMData *label=image->process(
"threshold.belowtozero",
Dict(
"minval",threshold));
14527 label->process_inplace(
"threshold.notzero");
14528 label->process_inplace(
"morph.object.label");
14529 int nobj=int(label->get_attr(
"maximum"))+1;
14530 vector<float> sden(nobj);
14531 for (
int i=0; i<nobj; i++) sden[i]=0;
14533 for (
int x=0;
x<nx;
x++){
14534 for (
int y=0;
y<ny;
y++){
14535 for (
int z=0; z<nz; z++){
14536 float v=image->get_value_at(
x,
y,z);
14540 int li=label->get_value_at(
x,
y,z);
14545 for (
int x=0;
x<nx;
x++){
14546 for (
int y=0;
y<ny;
y++){
14547 for (
int z=0; z<nz; z++){
14548 int li=label->get_value_at(
x,
y,z);
14551 image->set_value_at_fast(
x,
y,z,sden[li]);
14570 int nx = image->get_xsize();
14571 int ny = image->get_ysize();
14572 int nz = image->get_zsize();
14575 bool spanLeft, spanRight;
14576 vector<Vec3i> pvec;
14580 vector<float> centers(2);
14581 for (
int zz = 0; zz < nz; zz++) {
14583 for (
int yy = 0; yy < ny; yy++) {
14584 for (
int xx = 0; xx < nx; xx++) {
14585 if (image->get_value_at(xx,yy,zz)>0){
14586 pvec.push_back(
Vec3i(xx,yy,zz));
14587 if (writecenter && count<0){
14589 centers.push_back(cx);
14590 centers.push_back(cy);
14595 while(!pvec.empty())
14597 Vec3i v=pvec.back();
14598 int x=v[0],
y=v[1],z=v[2];
14602 while(y1 > 0 && image->get_value_at(
x,y1,zz)>0) y1--;
14604 spanLeft = spanRight = 0;
14608 if(image->get_value_at(
x,y1,zz)>0){
14609 image->set_value_at(
x,y1,zz,count);
14611 cx+=
x;cy+=y1;npx++;
14616 if(!spanLeft &&
x > 0 && image->get_value_at(
x-1,y1,zz)>0)
14618 pvec.push_back(
Vec3i(
x-1,y1,zz));
14621 else if(spanLeft &&
x > 0 && image->get_value_at(
x-1,y1,zz)<=0)
14625 if(!spanRight && x < nx - 1 && image->
get_value_at(
x+1,y1,zz)>0)
14627 pvec.push_back(
Vec3i(
x+1,y1,zz));
14630 else if(spanRight && x < nx - 1 && image->
get_value_at(
x+1,y1,zz)<=0)
14637 if (y1 >= ny-1 || image->get_value_at(
x,y1,zz)<=0)
14646 printf(
"%d objects.\n",-count);
14648 if (writecenter) image->set_attr(
"obj_centers",centers);
14662 int nx = image->get_xsize();
14663 int ny = image->get_ysize();
14664 int nz = image->get_zsize();
14674 imageCp= image ->
copy();
14675 float *data = image->get_data();
14676 size_t total_size = (size_t)nx * (
size_t)ny * (size_t)nz;
14679 float *data2 =
new float[total_size];
14680 for (
int k=0; k<nz; k++){
14682 printf(
"layer %d \n",k);
14683 size_t knxy = (size_t)k * nxy;
14684 for (
int j=0; j<ny; j++){
14686 for (
int i=0; i<nx; i++){
14687 if(i==0 || i==nx-1 || j==0 || j==ny-1)
14688 data[i+jnx+knxy]=0;
14690 if (data[i+jnx+knxy]>threshold)
14691 data[i+jnx+knxy]=1;
14693 data[i+jnx+knxy]=0;
14704 for (
int nt=0; nt<allt; nt++){
14706 for (
int st = 0; st<2; st++){
14707 memcpy(data2, data, total_size *
sizeof(
float));
14708 for (
int j = n; j < ny - n; j++) {
14710 for (
int i = n; i < nx - n; i++) {
14712 for (
int i2 = i - n; i2 <= i + n; i2++) {
14713 for (
int j2 = j - n; j2 <= j + n; j2++) {
14714 array[s] = data2[i2 + j2 * nx+knxy];
14724 printf(
"\t Iter %d, \t %d pixels changed\n",nt,cg);
14732 memcpy(data2, data, total_size *
sizeof(
float));
14733 for (
int j = n; j < ny - n; j++) {
14735 for (
int i = n; i < nx - n; i++) {
14737 for (
int i2 = i - n; i2 <= i + n; i2++) {
14738 for (
int j2 = j - n; j2 <= j + n; j2++) {
14739 array[s] = data2[i2 + j2 * nx+knxy];
14749 printf(
"\t %d corner pixels\n",cg);
14760 image->mult(*imageCp);
14773 for (
int i=0; i<9; i++){
14781 int order[9]={0,1,2,5,8,7,6,3,0};
14782 for (
int i=0; i<8; i++){
14783 if (array[order[i]]==0 && array[order[i+1]]>0){
14787 if (ap!=1 && step<2)
14791 if(array[order[1]]*array[order[3]]*array[order[5]]>0)
14793 if(array[order[3]]*array[order[5]]*array[order[7]]>0)
14798 if(array[order[1]]*array[order[3]]*array[order[7]]>0)
14800 if(array[order[1]]*array[order[5]]*array[order[7]]>0)
14806 if(array[order[1]]*array[order[3]]>0
14807 || array[order[3]]*array[order[5]]>0
14808 || array[order[5]]*array[order[7]]>0
14809 || array[order[7]]*array[order[1]]>0
14819 if(array[order[1]]*array[order[3]]>0
14820 || array[order[3]]*array[order[5]]>0
14847 int nx = image->get_xsize();
14848 int ny = image->get_ysize();
14849 int nz = image->get_zsize();
14860 float *data = image->get_data();
14861 size_t total_size = (size_t)nx * (
size_t)ny * (size_t)nz;
14863 float *data2 =
new float[total_size];
14864 memcpy(data2, data, total_size *
sizeof(
float));
14867 for (
int k=0; k<nz; k++){
14869 printf(
"layer %d \n",k);
14870 size_t knxy = (size_t)k * nxy;
14872 for (
int j=0; j<ny; j++){
14874 for (
int i=0; i<nx; i++){
14876 if (data[knxy+i+jnx]>threshold)
14877 data[knxy+i+jnx]=1;
14879 data[knxy+i+jnx]=0;
14888 for (
int j=1; j < ny-1; j++) {
14890 for (
int i=1; i<nx-1; i++) {
14892 if (data2[knxy+i+jnx]<=threshold)
14895 for (
int i2 = i-1; i2 <= i + 1; i2++) {
14896 for (
int j2 = j - 1; j2 <= j + 1; j2++) {
14897 array[s++] = data2[knxy+i2 + j2 * nx];
14901 int order[9]={0,1,2,5,8,7,6,3,0};
14902 for (
int oi=0; oi<8; oi++){
14903 if (array[order[oi]]<=threshold && array[order[oi+1]]>threshold){
14908 data[knxy+i+jnx]=1;
14914 printf(
"\t %d branch pixels\n",nbranch);
14919 for (
int j=1; j<ny; j++){
14921 for (
int i=0; i<nx; i++){
14922 data[knxy+i+jnx]=(1-data[knxy+i+jnx])*(maxdist+1);
14926 for (
int dt=0; dt<maxdist; dt++){
14927 for (
int j=1; j < ny-1; j++) {
14929 for (
int i=1; i<nx-1; i++) {
14931 if (data2[knxy+i+jnx]<=threshold)
14933 if (data[knxy+i+jnx]<=maxdist)
14936 for (
int i2=i-1; i2<=i+1; i2++) {
14937 for (
int j2=j-1; j2<=j+1; j2++) {
14938 db=(data[knxy+i2+j2*nx]==dt ? dt : db);
14941 data[knxy+i+jnx]=db+1;
14947 if (returnlength==
false){
14950 for (
int j=1; j < ny-1; j++) {
14952 for (
int i=1; i<nx-1; i++) {
14954 if (data2[knxy+i+jnx]<=threshold)
14956 if (data[knxy+i+jnx]>maxdist)
14959 for (
int i2=i-1; i2<=i+1; i2++) {
14960 for (
int j2=j-1; j2<=j+1; j2++) {
14961 nb+=(data2[knxy+i2+j2*nx]>threshold ? 1 : 0);
14965 data[knxy+i+jnx]=-data[knxy+i+jnx];
14966 data2[knxy+i+jnx]=threshold;
14973 for (
int dt=-maxdist; dt<-1; dt++){
14974 for (
int j=1; j < ny-1; j++) {
14976 for (
int i=1; i<nx-1; i++) {
14978 if (data2[knxy+i+jnx]<=threshold)
14980 if (data[knxy+i+jnx]<=0)
14983 for (
int i2=i-1; i2<=i+1; i2++) {
14984 for (
int j2=j-1; j2<=j+1; j2++) {
14985 rm=( data[knxy+i2+j2*nx]==dt ? 1 : rm );
14989 data2[knxy+i+jnx]=threshold;
14990 data[knxy+i+jnx]=dt+1;
14996 printf(
"\t %d branches removed\n",nend);
14999 if (returnlength==
false){
15000 memcpy(data, data2, total_size *
sizeof(
float));
15023 int nx = image->get_xsize();
15024 int ny = image->get_ysize();
15025 int nz = image->get_zsize();
15031 float *data = image->get_data();
15033 int *xlist=
new int[2*rad*4];
15034 int *ylist=
new int[2*rad*4];
15036 for (
int i=-rad; i<rad; i++){ xlist[count]=-rad; ylist[count]=i; count++;}
15037 for (
int i=-rad; i<rad; i++){ xlist[count]=i; ylist[count]=rad; count++;}
15038 for (
int i=-rad; i<rad; i++){ xlist[count]=rad; ylist[count]=-i; count++;}
15039 for (
int i=-rad; i<rad; i++){ xlist[count]=-i; ylist[count]=-rad; count++;}
15040 size_t nxy = nx * ny;
15041 for (
int k=0; k<nz; k++){
15043 printf(
"Processing layer %d \n",k);
15045 size_t knxy = (size_t)k * nxy;
15047 for (
int j=rad; j < ny-rad; j++) {
15049 for (
int i=rad; i<nx-rad; i++) {
15051 if (data[knxy+i+jnx]==0)
15054 for (
int i2=i-1; i2<=i+1; i2++) {
15055 for (
int j2=j-1; j2<=j+1; j2++) {
15056 nb+=(data[knxy+i2+j2*nx]>0 ? 1 : 0);
15061 for (
int ic=0; ic<count; ic++){
15062 int ix=i+xlist[ic], jy=j+ylist[ic];
15063 float v=data[knxy+ix+jy*nx];
15074 for (
int ig=1; ig<=rad; ig++){
15075 int ix=i-(float)xlist[cp]/rad*ig;
15076 int jy=j-(float)ylist[cp]/rad*ig;
15077 data[knxy+ix+jy*nx]=-1;
15083 for (
int j=rad; j < ny-rad; j++) {
15085 for (
int i=rad; i<nx-rad; i++) {
15086 if (data[knxy+i+jnx]==-1)
15087 data[knxy+i+jnx]=1;
15100 EMData* proc = image->copy();
15101 proc->process_inplace(
"math.distance.manhattan");
15112 int nx = image->get_xsize();
15113 int ny = image->get_ysize();
15114 int nz = image->get_zsize();
15115 int size = nx*ny*nz;
15118 for (
int i=0; i<nx; i++) {
15119 for (
int j=0; j<ny; j++) {
15120 for (
int k=0; k<nz; k++) {
15121 if (image->get_value_at(i,j,k) == 1) {
15122 image->set_value_at_fast(i,j,k,0);
15124 image->set_value_at_fast(i,j,k,size+nx);
15125 float north =
Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i-1,j,k)+1);
15126 float west =
Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j-1,k)+1);
15127 float above =
Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j,k-1)+1);
15128 if (i>0) image->set_value_at_fast(i,j,k,north);
15129 if (j>0) image->set_value_at_fast(i,j,k,west);
15130 if (k>0) image->set_value_at_fast(i,j,k,above);
15137 for (
int i=nx-2; i>=0; i--) {
15138 for (
int j=ny-2; j>=0; j--) {
15139 for (
int k=nz-2; k>=0; k--) {
15140 if (image->get_value_at(i,j,k) == 1) {
15141 image->set_value_at_fast(i,j,k,0);
15143 float south =
Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i+1,j,k)+1);
15144 float east =
Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j+1,k)+1);
15145 float below =
Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j,k+1)+1);
15146 if (i+1<nx) image->set_value_at_fast(i,j,k,south);
15147 if (j+1<ny) image->set_value_at_fast(i,j,k,east);
15148 if (k+1<nz) image->set_value_at_fast(i,j,k,below);
15157 EMData* proc = image->copy();
15158 proc->process_inplace(
"morph.dilate.binary",
params);
15173 int nx = image->get_xsize();
15174 int ny = image->get_ysize();
15175 int nz = image->get_zsize();
15176 int imsize = nx*ny*nz;
15178 EMData *binarized = image->process(
"threshold.binary",
Dict(
"value",thresh));
15179 memcpy(image->get_data(),binarized->get_data(),imsize*
sizeof(
float));
15183 if ( radius == 0 || iters == 0) {
15189 for (
int iter = 0; iter < iters; iter++) {
15190 image->process_inplace(
"math.distance.manhattan");
15191 for (
int i=0; i < nx; i++){
15192 for (
int j=0; j < ny; j++){
15193 for (
int k=0; k < nz; k++) {
15194 image->set_value_at_fast(i,j,k,(image->get_value_at(i,j,k)<=radius)?1:0);
15205 EMData* proc = image->copy();
15206 proc->process_inplace(
"morph.erode.binary",
params);
15221 int nx = image->get_xsize();
15222 int ny = image->get_ysize();
15223 int nz = image->get_zsize();
15224 int imsize = nx*ny*nz;
15226 EMData *binarized = image->process(
"threshold.binary",
Dict(
"value",thresh));
15227 memcpy(image->get_data(),binarized->get_data(),imsize*
sizeof(
float));
15231 if ( radius == 0 || iters == 0) {
15235 for (
int iter = 0; iter < iters; iter++) {
15236 image->process_inplace(
"math.distance.manhattan");
15237 for (
int i=0; i < nx; i++){
15238 for (
int j=0; j < ny; j++){
15239 for (
int k=0; k < nz; k++) {
15240 image->set_value_at_fast(i,j,k,(image->get_value_at(i,j,k)<=radius)?1:0);
15249 EMData* proc = image->copy();
15250 proc->process_inplace(
"morph.open.binary",
params);
15258 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15260 for (
int i = 0; i < iters; i++) image->process_inplace(
"morph.erode.binary",
params);
15261 for (
int i = 0; i < iters; i++) image->process_inplace(
"morph.dilate.binary",
params);
15266 EMData* proc = image->copy();
15267 proc->process_inplace(
"morph.close.binary",
params);
15275 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15277 for (
int i = 0; i < iters; i++) image->process_inplace(
"morph.dilate.binary",
params);
15278 for (
int i = 0; i < iters; i++) image->process_inplace(
"morph.erode.binary",
params);
15283 EMData* proc = image->copy();
15284 proc->process_inplace(
"morph.gradient.internal",
params);
15292 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15294 for (
int i = 0; i < iters; i++){
15295 EMData *cpy = image->copy();
15296 cpy->process_inplace(
"morph.erode.binary",
params);
15304 EMData* proc = image->copy();
15305 proc->process_inplace(
"morph.gradient.external",
params);
15313 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15315 for (
int i = 0; i < iters; i++){
15316 EMData *cpy = image->copy();
15317 image->process_inplace(
"morph.dilate.binary",
params);
15325 EMData* proc = image->copy();
15326 proc->process_inplace(
"morph.gradient",
params);
15334 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15336 for (
int i = 0; i < iters; i++){
15337 EMData *eroded = image->process(
"morph.erode.binary",
params);
15338 image->process_inplace(
"morph.dilate.binary",
params);
15339 image->sub(*eroded);
15346 EMData* proc = image->copy();
15347 proc->process_inplace(
"morph.tophat.binary",
params);
15355 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15357 for (
int i = 0; i < iters; i++){
15358 EMData* open = image->process(
"morph.open.binary",
params);
15366 EMData* proc = image->copy();
15367 proc->process_inplace(
"morph.blackhat.binary",
params);
15375 image->process_inplace(
"threshold.binary",
Dict(
"value",thresh));
15377 for (
int i = 0; i < iters; i++){
15378 EMData* close = image->process(
"morph.close.binary",
params);
15379 image->sub(*close);
15386 EMData* proc = image->copy();
15387 proc->process_inplace(
"misc.zthick",
params);
15394 int nx = image->get_xsize();
15395 int ny = image->get_ysize();
15396 int nz = image->get_zsize();
15398 for (
int i=0; i<nx; i++) {
15399 for (
int j=0; j<ny; j++) {
15401 int dep=0, starti=0;
15402 bool counting=
false;
15403 for (
int k=0; k<nz; k++) {
15404 if (image->get_value_at(i,j,k)>thresh){
15417 for (
int u=starti; u<k; u++){
15418 image->set_value_at_fast(i,j,u,dep);
15434 EMData* proc = image->copy();
15435 proc->process_inplace(
"math.multamplitude",
params);
15442 float* data = image->get_data();
15443 float*
mult = amp->get_data();
15445 int nx = image->get_xsize();
15446 int ny = image->get_ysize();
15447 int nz = image->get_zsize();
15451 int anx = amp->get_xsize();
15452 int any = amp->get_ysize();
15453 int anz = amp->get_zsize();
15464 if (( (nx==anx*2) && (ny==any) && (nz==anz) )==
false)
15469 for (
int i=0; i<sz; i++){
15476#ifdef SPARX_USING_CUDA
15481#include "sparx/cuda/cuda_mpi_kmeans.h"
15482MPICUDA_kmeans::MPICUDA_kmeans() {
15496MPICUDA_kmeans::~MPICUDA_kmeans() {
15497 if (h_IM)
delete h_IM;
15498 if (h_ASG)
delete h_ASG;
15499 if (h_AVE)
delete h_AVE;
15500 if (h_dist)
delete h_dist;
15501 if (h_AVE2)
delete h_AVE2;
15502 if (h_im2)
delete h_im2;
15503 if (h_NC)
delete h_NC;
15504 if (params)
delete params;
15507#include "sparx/cuda/cuda_mpi_kmeans.h"
15508int MPICUDA_kmeans::setup(
int extm,
int extN,
int extn,
int extK,
int extn_start) {
15513 n_start = extn_start;
15520 NB = size_dist / BLOCK_SIZE;
15521 ins_BLOCK = NB * BLOCK_SIZE;
15523 h_IM = (
float*)malloc(size_IM *
sizeof(
float));
15524 if (h_IM == 0)
return 1;
15525 h_im = &h_IM[n_start * m];
15527 h_AVE = (
float*)malloc(size_AVE *
sizeof(
float));
15528 if (h_AVE == 0)
return 1;
15530 h_ASG = (
unsigned short int*)malloc(N *
sizeof(
unsigned short int));
15531 if (h_ASG == 0)
return 1;
15532 h_asg = &h_ASG[n_start];
15534 h_AVE2 = (
float*)malloc(K *
sizeof(
float));
15535 if (h_AVE2 == 0)
return 1;
15537 h_im2 = (
float*)malloc(n *
sizeof(
float));
15538 if (h_im2 == 0)
return 1;
15540 h_dist = (
float*)malloc(size_dist *
sizeof(
float));
15541 if (h_dist == 0)
return 1;
15543 h_NC = (
unsigned int*)malloc(K *
sizeof(
unsigned int));
15544 if (h_NC == 0)
return 1;
15546 params = (
int*)malloc(8 *
sizeof(
int));
15547 if (params == 0)
return 1;
15553 params[5] = BLOCK_SIZE;
15555 params[7] = ins_BLOCK;
15562void MPICUDA_kmeans::append_flat_image(
EMData* im,
int pos) {
15564 for (
int i = 0; i < m ; ++i) h_IM[pos * m + i] = (*im)(i);
15569int MPICUDA_kmeans::init_mem(
int numdev) {
15571 float** hd_AVE = NULL;
15572 float** hd_im = NULL;
15573 float** hd_dist = NULL;
15577 stat = cuda_mpi_init(h_im, hd_im, hd_AVE, hd_dist, size_im, size_AVE, size_dist, numdev);
15585void MPICUDA_kmeans::compute_im2() {
15586 for (
int i = 0; i < n; i++) {
15588 for (
int j = 0; j < m; j++) h_im2[i] += (h_im[i * m + j] * h_im[i * m + j]);
15593int MPICUDA_kmeans::random_ASG(
long int rnd) {
15598 std::cout<<
"111111111 number of image==="<<N<<
"number cluster=="<<K<<
"img size"<<m<<std::endl;
15599 for (k = 0; k < K; k++) h_NC[k] = 0;
15602 for (i = 0; i < N; i++) {
15603 h_ASG[i] = rand() % K;
15608 while (k > 0 && flag) {
15610 if (h_NC[k] <= 1) {
15616 for (k = 0; k < K; k++) h_NC[k] = 0;
15618 if (flag == 1) ret = 0;
15626vector <int> MPICUDA_kmeans::get_ASG() {
15627 vector <int> ASG(h_ASG, &h_ASG[N]);
15632vector <int> MPICUDA_kmeans::get_asg() {
15633 vector <int> asg(h_asg, &h_asg[n]);
15638void MPICUDA_kmeans::compute_NC() {
15639 for (
int i = 0; i < K; ++i) h_NC[i] = 0;
15640 for (
int i = 0; i < N; ++i) h_NC[h_ASG[i]]++;
15644vector <int> MPICUDA_kmeans::get_NC() {
15645 vector <int> NC(h_NC, &h_NC[K]);
15650void MPICUDA_kmeans::set_ASG(
const vector <int>& ASG) {
15651 for (
int i = 0; i < N ; ++i) h_ASG[i] = ASG[i];
15655void MPICUDA_kmeans::set_NC(
const vector <int>& NC) {
15656 for (
int i = 0; i < K; ++i) h_NC[i] = NC[i];
15660int MPICUDA_kmeans::get_ct_im_mv() {
15665void MPICUDA_kmeans::set_T(
float extT) {
15670float MPICUDA_kmeans::get_T() {
15675void MPICUDA_kmeans::compute_AVE() {
15677 int i, j, c, d, ind;
15679 for (i = 0; i < size_AVE; ++i) h_AVE[i] = 0.0f;
15680 for (i = 0; i < N; ++i) {
15683 for (j = 0; j < m; ++j) h_AVE[c + j] += h_IM[d + j];
15685 for (i = 0; i < K; i++) {
15687 for (j = 0 ; j < m; j++) {
15689 h_AVE[ind] /= (float)h_NC[i];
15690 buf += (h_AVE[ind] * h_AVE[ind]);
15703void MPICUDA_kmeans::set_AVE(
EMData* im,
int pos) {
15704 for (
int i = 0; i < m ; ++i) h_AVE[pos * m + i] = (*im)(i);
15708vector<EMData*> MPICUDA_kmeans::get_AVE() {
15709 vector<EMData*> ave(K);
15710 for (
int k = 0; k < K; ++k) {
15712 im->set_size(m, 1, 1);
15713 float *ptr = im->get_data();
15714 for (
int i = 0; i < m; ++i) {ptr[i] = h_AVE[k * m + i];}
15715 ave[k] = im->copy();
15722int MPICUDA_kmeans::one_iter() {
15723 int status = cuda_mpi_kmeans(h_AVE, d_AVE, h_dist, d_dist, d_im, h_im2, h_AVE2, h_asg, h_NC, params);
15763int MPICUDA_kmeans::one_iter_SA() {
15764 int status = cuda_mpi_kmeans_SA(h_AVE, d_AVE, h_dist, d_dist, d_im, h_im2, h_AVE2, h_asg, h_NC, T, params);
15770vector <float> MPICUDA_kmeans::compute_ji() {
15771 int status = cuda_mpi_dist(h_AVE, d_AVE, h_dist, d_dist, d_im, n, K, m);
15772 vector <float> ji(K);
15775 for (i = 0; i < K; ++i) ji[i] = -1.0;
15778 for (i = 0; i < n; ++i) ji[h_asg[i]] += (h_im2[i] + h_AVE2[h_asg[i]] - 2 * h_dist[i * K + h_asg[i]]);
15783float MPICUDA_kmeans::compute_tt() {
15798 vector <float> ji(K);
15801 for (i = 0; i < n; ++i)
15804 for ( j=0; j<m; j++) {
15805 temp = (h_im[i*m+j] -h_AVE[ h_asg[i]*m+j]);
15806 dist = dist + temp*temp;
15808 ji[h_asg[i]] = ji[h_asg[i]]+ dist;
15812 for (i =0; i<K;i++)
15819vector <float> MPICUDA_kmeans::compute_criterion(
const vector <float>& Ji) {
15822 float Tr_AVE = 0.0f;
15823 float v_max = 0.0f;
15824 float* S_AVE2 = (
float*)calloc(m,
sizeof(
float));
15825 float* S_AVE = (
float*)calloc(m,
sizeof(
float));
15826 vector <float> crit(4);
15829 for (i = 0; i < K; ++i) Je += (Ji[i] /
float(m));
15832 for (i = 0; i < K; ++i) {
15833 for (j = 0; j < m; ++j) {
15834 S_AVE[j] += h_AVE[i * m + j];
15835 S_AVE2[j] += (h_AVE[i * m + j] * h_AVE[i * m +j]);
15838 buf = 1 / (float)K;
15839 for (i = 0; i < m; ++i) Tr_AVE += (buf * (S_AVE2[i] - buf * S_AVE[i] * S_AVE[i]));
15841 crit[1] = Tr_AVE * Je;
15843 crit[2] = (Tr_AVE * (float)(N - K)) / (Je * (
float)(K - 1));
15845 for (i = 0; i < K; ++i) {
15847 for (j = 0; j < K; ++j) {
15850 for (k = 0; k < m; ++k) buf += ((h_AVE[j * m + k] - h_AVE[i * m + k]) * (h_AVE[j * m + k] - h_AVE[i * m + k]));
15851 buf = (Ji[i] / (float)h_NC[i] + Ji[j] / (
float)h_NC[j]) * ((
float)m / buf);
15853 if (buf > v_max) v_max = buf;
15857 crit[3] /= (float)K;
15864int MPICUDA_kmeans::shutdown() {
15865 return cuda_mpi_shutdown(d_im, d_AVE, d_dist);
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual float get_sigma(EMData *)
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
float get_sigma(EMData *image)
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *in)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void create_kernel() const =0
virtual void process_pixel(float *pixel, float, float, float, float *area_matrix) const
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
Averager class defines a way to do averaging on a set of images.
virtual EMData * finish()=0
Finish up the averaging and return the result.
virtual void add_image(EMData *image)
To add an image to the Averager.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
Operates on two images, returning an image containing the maximum/minimum/multiplied pixel (etc,...
virtual EMData * process(EMData *image)
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image, Dict ¶ms)
Boolean shrink an image inplace.
EMData * process(const EMData *const image, Dict ¶ms)
Boolean shrink an image, returning the processed image.
BoxStatProcessor files are a kind of neighborhood processors.
virtual EMData * process(EMData *image)
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_pixel(float *pixel, const float *array, int n) const =0
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
int process_pixel(float *data, float *array, int step)
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
float inner_radius_square
void calc_locals(EMData *image)
float outer_radius_square
void process_inplace(EMData *image)
To process an image in-place.
The base class for fourier space processor working on individual pixels.
virtual void process_pixel(float *x) const =0
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
CoordinateProcessor applies processing based on a pixel's value and it coordinates.
virtual void calc_locals(EMData *)
virtual bool is_valid() const
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_pixel(float *pixel, int xi, int yi, int zi) const =0
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
Ctf is the base class for all CTF model.
virtual void compute_2d_complex(EMData *img, CtfType t, XYData *struct_factor=0)=0
virtual vector< float > compute_1d(int size, float ds, CtfType t, XYData *struct_factor=0)=0
void process_inplace(EMData *image)
To process an image in-place.
string get_name() const
Get the processor's name.
void process_inplace(EMData *image)
To process an image in-place.
Dict is a dictionary to store <string, EMObject> pair.
size_t size() const
Ask the Dictionary for its size.
void put(const string &key, EMObject val)
Put the value/key pair into the dictionary probably better to just use operator[].
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
EMObject get(const string &key) const
Get the EMObject corresponding to the particular key Probably better to just use operator[].
void process_inplace(EMData *image)
To process an image in-place.
string get_name() const
Get the processor's name.
virtual EMData * process(const EMData *const image)
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void create_radial_func(vector< float > &radial_mask) const
EMAN2Ctf is the default CTF model used in EMAN2.
vector< float > compute_1d(int size, float ds, CtfType type, XYData *struct_factor=0)
void copy_from(const Ctf *new_ctf)
EMData stores an image's data and defines core image processing routines.
void translate(float dx, float dy, float dz)
Translate this image.
EMData * get_clip(const Region &area, const float fill=0) const
Get an inclusive clip.
void apply_radial_func(float x0, float dx, vector< float >array, bool interp=true)
multiplies by a radial function in fourier space.
vector< float > calc_radial_dist(int n, float x0, float dx, int inten)
calculates radial distribution.
vector< float > calc_hist(int hist_size=128, float hist_min=0, float hist_max=0, const float &brt=0.0f, const float &cont=1.0f)
Calculates the histogram of 'this' image.
void transform(const Transform &t)
Rotate then translate the image.
EMData * convolute(EMData *with)
Convolutes 2 data sets.
void clip_inplace(const Region &area, const float &fill_value=0)
Clip the image inplace - clipping region must be smaller than the current region internally memory is...
EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
static void * em_calloc(const size_t nmemb, const size_t size)
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void fft_resample(EMData *to, const EMData *const from, const float &sample_rate)
An internal function that encapsulates a routine common to both process and process inplace.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(EMData const *image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
Factory is used to store objects to create new instances.
static T * get(const string &instance_name)
static vector< string > get_list()
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
FloatPoint defines a float-coordinate point in a 1D/2D/3D space.
virtual void preprocess(EMData *)
virtual void create_radial_func(vector< float > &radial_mask, EMData *image) const =0
void process_inplace(EMData *image)
To process an image in-place.
static const float kernel[12][12][12]
static const float kernel[9][9][9]
base class for Fourier filters
virtual void preprocess(EMData *image)
virtual void create_radial_func(vector< float > &radial_mask) const =0
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
Fourier origin shift the image in the forward direction.
virtual void process_inplace(EMData *image)
Fourier origin shift the image in the backwards direction Should only be called after the application...
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
string get_name() const
Get the processor's name.
void process_inplace(EMData *image)
To process an image in-place.
string get_name() const
Get the processor's name.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void create_radial_func(vector< float > &radial_mask, EMData *image) const
virtual void preprocess(EMData *image)
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * create_processor_image() const =0
virtual void process_inplace(EMData *image)
To process an image in-place.
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
void assert_valid_aspect(const vector< int > &translation, const EMData *const image) const
Check that the particular aspect is valid.
virtual EMData * process(const EMData *const image)
virtual void process_inplace(EMData *image)
Region get_clip_region(vector< int > &translation, const EMData *const image) const
Get the clip region that will achieve the desired translation.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void create_kernel() const
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void create_radial_func(vector< float > &radial_mask) const
void create_radial_func(vector< float > &radial_mask) const
void create_radial_func(vector< float > &radial_mask) const
void process_inplace(EMData *image)
To process an image in-place.
void set_level(int level)
void error(const char *format,...)
log an error message.
void create_radial_func(vector< float > &radial_mask, EMData *image) const
void create_radial_func(vector< float > &radial_mask) const
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void calc_locals(EMData *image)
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void create_radial_func(vector< float > &radial_mask, EMData *image) const
void accrue_mean_one_p_five(EMData *to, const EMData *const from)
Accrue the local mean in the image 'from' to the image 'to' using the the special case shrink factor ...
virtual void process_inplace(EMData *image)
Mean shrink inplace.
virtual EMData * process(const EMData *const image)
The meanshrink processor has its own process function to minise memory usage - if this function was n...
void accrue_mean(EMData *to, const EMData *const from, const int shrinkfactor)
Accrue the local mean in the image 'from' to the image 'to' using the given shrinkfactor An internal ...
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *in)
To process an image in-place.
float radprofile(float r, int type)
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
float calc_mean(EMData *image) const
float calc_mean(EMData *image) const
float calc_mean(EMData *image) const
float calc_mean(EMData *image) const
void process_inplace(EMData *image)
To process an image in-place.
float calc_mean(EMData *image) const
float calc_sigma(EMData *image) const
Base class for normalization processors.
virtual float calc_sigma(EMData *image) const
void process_inplace(EMData *image)
To process an image in-place.
virtual float calc_mean(EMData *image) const =0
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
float calc_mean(EMData *image) const
void process_inplace(EMData *image)
To process an image in-place.
float calc_sigma(EMData *image) const
float calc_sigma(EMData *image) const
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void fourier_phaseshift180(EMData *image)
fourier_phaseshift180 - fourier phase shift by 180 this function is called internally if the argument...
void swap_corners_180(EMData *image)
swap_corners_180 - works on 2D and 3D images
void swap_central_slices_180(EMData *image)
swap_central_slices_180 - works on 2D and 3D images
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
Pixel describes a 3D pixel's coordinates and its intensity value.
Typical usage of Processors are as follows:
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)=0
To process an image in-place.
virtual string get_name() const =0
Get the processor's name.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
string get_name() const
Get the processor's name.
void process_inplace(EMData *image)
To process an image in-place.
The wrapper class for gsl's random number generater.
void set_seed(unsigned long long seed)
Set the seed for the random number generator.
static Randnum * Instance()
float get_gauss_rand(float mean, float sigma) const
Return a Gaussian random number.
float get_frand(double lo=0.0, double hi=1.0) const
This function returns a random float from lo inclusive to hi.
virtual void process_inplace(EMData *image)
To process an image in-place.
The base class for real space processor working on individual pixels.
void process_inplace(EMData *image)
To process an image in-place.
virtual void calc_locals(EMData *)
virtual void process_pixel(float *x) const =0
void process_inplace(EMData *image)
To process an image in-place.
string get_name() const
Get the processor's name.
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
void create_radial_func(vector< float > &radial_mask, EMData *image) const
string get_name() const
Get the processor's name.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
Symmetry3D - A base class for 3D Symmetry objects.
static vector< Transform > get_symmetries(const string &symmetry)
virtual int point_in_which_asym_unit(const Vec3f &v) const
A function that will determine in which asymmetric unit a given vector resides The asymmetric unit 'n...
virtual vector< Transform > get_syms() const
virtual void process_inplace(EMData *image)
Make an image where the axes (where x,y and z=0) are some nono zero value.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void preprocess(EMData *image)
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual string get_name() const
Get the processor's name.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual string get_name() const
Get the processor's name.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
Make a useful tomographic phantom image.
void insert_rectangle(EMData *image, const Region ®ion, const float &value, const Transform &t3d=Transform())
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
See Processor comments for more details.
virtual void process_inplace(EMData *image)
See Processor comments for more details.
static void calc_least_square_fit(size_t nitems, const float *data_x, const float *data_y, float *p_slope, float *p_intercept, bool ignore_zero, float absmax=0)
calculate the least square fit value.
static int hypot3sq(int x, int y, int z)
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
static float angle_norm_pi(float in)
Normalize an angle in radians so it is in the -pi to pi range.
static std::complex< float > trilinear_interpolate_complex(std::complex< float > p1, std::complex< float > p2, std::complex< float > p3, std::complex< float > p4, std::complex< float > p5, std::complex< float > p6, std::complex< float > p7, std::complex< float > p8, float t, float u, float v)
Calculate trilinear interpolation.
static short hypot_fast_int(int x, int y)
Euclidean distance in 2D for integers computed fast using a cached lookup table.
static float angle_sub_2pi(float x, float y)
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.
static int square(int n)
Calculate a number's square.
static int fast_floor(float x)
A fast way to calculate a floor, which is largest integral value not greater than argument.
static int goodf(const float *p_f)
Check whether a number is a good float.
static float get_frand(int low, int high)
Get a float random number between low and high, [low, high)
static float hypot3(int x, int y, int z)
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
static int round(float x)
Get ceiling round of a float number x.
static int calc_best_fft_size(int low)
Search the best FFT size with good primes.
static void save_data(const vector< float > &x_array, const vector< float > &y_array, const string &filename)
Save (x y) data array into a file.
static float trilinear_interpolate(float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float t, float u, float v)
Calculate trilinear interpolation.
static int get_min(int f1, int f2)
Get the minimum of 2 numbers.
static float bilinear_interpolate(float p1, float p2, float p3, float p4, float t, float u)
Calculate bilinear interpolation.
static float square_sum(float x, float y)
Calcuate (x*x + y*y).
static float hypot_fast(int x, int y)
Euclidean distance in 2D for integers computed fast using a cached lookup table.
static float hypot2(float x, float y)
Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);.
static bool IsPower2(int x)
Return true if an integer is positive and is power of 2.
The Vec2 is precisely the same as Vec3 except it works exclusively in 2D Note there are convenient ty...
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
virtual void process_inplace(EMData *)
To process an image in-place.
virtual string get_name() const
Get the processor's name.
virtual void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
XYData defines a 1D (x,y) data set.
void make_gauss(int n, float xmax, float width)
void set_x(size_t i, float x)
float get_y(size_t i) const
float get_yatx(float x, bool outzero=true)
void set_y(size_t i, float y)
float get_x(size_t i) const
vector< float > get_state() const
int read_file(const string &filename)
void set_state(vector< float >)
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
virtual void process_inplace(EMData *image)
To process an image in-place.
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
void process_inplace(EMData *image)
To process an image in-place.
void process_inplace(EMData *image)
To process an image in-place.
VolumeData * getVolumeData()
void emdata_phaseorigin_to_corner(float *data, const int nx, const int ny, const int nz)
void emdata_phaseorigin_to_center(float *data, const int nx, const int ny, const int nz)
float * emdata_transform_cuda(const float *const m, const int nx, const int ny, const int nz)
void emdata_rotate_180(float *data, const int nx, const int ny)
Rotates by 180 degrees using memory swapping, uses shared memory for efficiency Works on 2D images - ...
#define Assert(s)
Define Assert() function that is effective only when -DDEBUG is used.
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
EMData * log() const
return natural logarithm image for a image
void mult(int n)
multiply an integer number to each pixel value of the image.
void set_value_at(Vec3i loc, float val)
set_value_at with Vec3i
EMData * sqrt() const
return square root of current image
float get_value_at(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
EMData * log10() const
return base 10 logarithm image for a image
EMData * real() const
return real part of a complex image as a real image format, if this image is a real image,...
EMData * phase() const
return phase part of a complex image as a real image format
void div(float f)
make each pixel value divided by a float number.
void write_image(const string &filename, int img_index=0, EMUtil::ImageType imgtype=EMUtil::IMAGE_UNKNOWN, bool header_only=false, const Region *region=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
write the header and data out to an image.
void process_inplace(const string &processorname, const Dict ¶ms=Dict())
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
#define InvalidParameterException(desc)
#define InvalidValueException(val, desc)
#define ImageFormatException(desc)
#define InvalidStringException(str, desc)
#define ImageDimensionException(desc)
#define UnexpectedBehaviorException(desc)
#define InvalidCallException(desc)
#define NullPointerException(desc)
map< string, vector< string > > group_processors()
int multi_processors(EMData *image, vector< string > processornames)
double length(const Vector3 &v)
map< string, vector< string > > dump_processors_list()
#define FFTRADIALOVERSAMPLE
friend bool operator<(const WSsortlist &l, const WSsortlist &r)