Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/C-CINA/focus
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbiyani committed May 17, 2017
2 parents d932d5f + af64a10 commit 98f42ad
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 63 deletions.
4 changes: 2 additions & 2 deletions apps/focus/AutoImportWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ void AutoImportWindow::importImage() {
conf->set("TLTANG", "-", false);
conf->set("TAXA", "-", false);
conf->set("TANGL", "-", false);
conf->set("defocus", "-", false);
conf->set("defocus_defocus", "-", false);
conf->set("defocus", "0.0,0.0,0.0", false);
conf->set("defocus_defocus", "0.0,0.0,0.0", false);

//Set the parameters from filename
for(QString param : fileNameParams.keys()) {
Expand Down
10 changes: 9 additions & 1 deletion apps/src/widgets/ImageViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ void ImageViewer::loadFile(const QString &fileName, const QString& extension, bo
if(fileName.isEmpty() || extension.isEmpty()) return;

if (!QFileInfo(fileName).exists()) {
setText(notFoundMessage_);
if (extension_ == "mrc" && QFileInfo(fileName+".png").exists()) {
QImage image;
image = QImage(fileName+".png");
imageLabel->setPixmap(QPixmap::fromImage(image));
resizeWidgets();
}
else {
setText(notFoundMessage_);
}
return;
}

Expand Down
38 changes: 31 additions & 7 deletions scripts/proc/focus_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ def RotationalAverage( img ):

return rotavg

def RadialProfile( img ):
# Compute the 1D radial profile of a 2D image or 3D volume:

rmesh = RadialIndices( img.shape, rounding=True )[0]

profile = np.zeros( len( np.unique( rmesh ) ) )
j = 0
for r in np.unique( rmesh ):

idx = rmesh == r
profile[j] = img[idx].mean()
j += 1

return profile

def RadialFilter( img, filt, return_filter = False ):
# Given a list of factors 'filt', radially multiplies the Fourier Transform of 'img' by the corresponding term in 'filt'

Expand All @@ -121,11 +136,11 @@ def RadialFilter( img, filt, return_filter = False ):

if not return_filter:

return np.fft.irfftn( ft )
return np.fft.irfftn( ft, s=img.shape )

else:

return np.fft.irfftn( ft ), filter2d
return np.fft.irfftn( ft, s=img.shape ), filter2d

def SoftMask( imsize = [100, 100], radius = 0.5, width = 6.0, rounding=False, xyz=[0,0,0] ):
# Generates a circular or spherical mask with a soft cosine edge
Expand Down Expand Up @@ -204,7 +219,7 @@ def FilterGauss( img, apix=1.0, lp=-1, hp=-1, return_filter=False ):

ft = np.fft.rfftn( img )

filtered = np.fft.irfftn( ft * bandpass )
filtered = np.fft.irfftn( ft * bandpass, s=img.shape )

if return_filter:

Expand All @@ -228,7 +243,7 @@ def FilterBfactor( img, apix=1.0, B=0.0, return_filter=False ):

ft = np.fft.rfftn( img )

filtered = np.fft.irfftn( ft * bfac )
filtered = np.fft.irfftn( ft * bfac, s=img.shape )

if return_filter:

Expand Down Expand Up @@ -309,7 +324,7 @@ def HighResolutionNoiseSubstitution( img, lp = -1, apix = 1.0 ):

ftnew = amps * ( np.cos( phases ) + 1j*np.sin( phases ) )

return np.fft.irfftn( ftnew )
return np.fft.irfftn( ftnew, s=img.shape )

def Resample( img, newsize=None, apix=1.0, newapix=None ):
# Resizes a real image or volume by cropping/padding its Fourier Transform, i.e. resampling.
Expand Down Expand Up @@ -343,7 +358,7 @@ def NormalizeImg( img, mean=0.0, std=1.0, radius = -1 ):

return (img - m + mean) * std / s

def FCC( volume1, volume2, phiArray = [0.0] ):
def FCC( volume1, volume2, phiArray = [0.0], invertCone = False, xy_only = False, z_only = False ):
"""
Fourier conic correlation
Expand All @@ -366,6 +381,13 @@ def FCC( volume1, volume2, phiArray = [0.0] ):
[M,N,P] = volume1.shape
[zmesh, ymesh, xmesh] = np.mgrid[ -M/2:M/2, -N/2:N/2, -P/2:P/2 ]
rhomax = np.int( np.ceil( np.sqrt( M*M/4.0 + N*N/4.0 + P*P/4.0) ) + 1 )
if xy_only:
zmesh *= 0
rhomax = np.int( np.ceil( np.sqrt( N*N/4.0 + P*P/4.0) ) + 1 )
if z_only:
xmesh *= 0
ymesh *= 0
rhomax = rhomax = np.int( np.ceil( np.sqrt( M*M/4.0 ) ) + 1 )
rhomesh = np.sqrt( xmesh*xmesh + ymesh*ymesh + zmesh*zmesh )
phimesh = np.arccos( zmesh / rhomesh )
phimesh[M/2,N/2,P/2] = 0.0
Expand Down Expand Up @@ -402,6 +424,8 @@ def FCC( volume1, volume2, phiArray = [0.0] ):
rhoround_conic = rhoround
else:
conic = np.ravel( (phimesh <= phiAngle ) + ( (np.abs(phimesh - np.pi)) <= phiAngle ) )
if invertCone:
conic = np.invert( conic )
rhoround_conic = rhoround[conic]
fft1_conic = fft1[conic]
conj_fft2_conic = conj_fft2[conic]
Expand All @@ -410,7 +434,7 @@ def FCC( volume1, volume2, phiArray = [0.0] ):
Norm1 = np.bincount( rhoround_conic, np.abs(fft1_conic)*np.abs(fft1_conic) )
Norm2 = np.bincount( rhoround_conic, np.abs(conj_fft2_conic)*np.abs(conj_fft2_conic) )

goodIndices = np.argwhere( (Norm1 * Norm2) > 0.0 )
goodIndices = np.argwhere( (Norm1 * Norm2) > 0.0 )[:-1]
FCC_normed[goodIndices,J] = FCC[goodIndices] / np.sqrt( Norm1[goodIndices] * Norm2[goodIndices] )

return FCC_normed
Expand Down
Loading

0 comments on commit 98f42ad

Please sign in to comment.