Difference between revisions of "Construction of masks"

From Dynamo
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 19: Line 19:
 
Here, you would enclose an area on a 2d slice that includes the Z axis (i.e., a section from an X-view or a Z-view), and then let ''Dynamo'' rotate the area around the central Z axis to create a revolution solid.
 
Here, you would enclose an area on a 2d slice that includes the Z axis (i.e., a section from an X-view or a Z-view), and then let ''Dynamo'' rotate the area around the central Z axis to create a revolution solid.
  
This can be done with {{t|dynamo_mapview}}.  Open your template, go to an X view, select one slice and press on [shift+S]. A second window will pop up, zooming into the selected slice. When you finish, the message area will tell you the name of the file containing the the created revolution solid.
+
This can be done with {{t|dynamo_mapview}}.  Open your template, go to an X view, select one slice and press on [shift+S]. A second window will pop up, zooming into the selected slice. When you finish, the message area will tell you the name of the file containing the the created revolution solid, by default {{t|temp_drawn_revolution_mask.em}}.  You can secondary click on it to directly show in Chimera.
  
[[File: mapview_handdraw_slice_zoom.png|thumb|center|300px| The blue square is the control for the handdrawn shape. Solid red are levels interpolated between the user-drawn light levels]]
+
[[File: mapview_select_slice_for_revolution.png|thumb|center|600px| Select a central section representing an x-view and click shift+S]]
 +
 
 +
[[File: mapview_handdraw_slice_zoom.png|thumb|center|300px| Draw the line and click secondary click to close the line]]
 +
 
 +
[[File: mapview_revolution_mask_chimera.png|thumb|center|300px| Revolution solid, visualized in Chimera]]
  
 
=== Slide by slide ===
 
=== Slide by slide ===
  
You can edit a volume as a montage of orthoslices, and handdraw on each of them, or onto a selection of them an let ''Dynamo'' interpolate on the other sections:
+
You can edit a volume as a montage of orthoslices, and handdraw on each of them, or onto a selection of them an let ''Dynamo'' interpolate on the other sections. This interpolation is purely geometrical and doesn't take the graymap into account.
 +
 
 +
You can test the procedure with the shipped phantom template.
  
 
<tt>dpkvol.montage('template.em');</tt>
 
<tt>dpkvol.montage('template.em');</tt>
  
Then choose the <tt>Mask</tt> tab to created a control for free handdraw of shapes on each slice. Secondary click on a drawn level will offer a menu of options, like interpolating between user-marked levels, or converting the current work into a cube.
+
Then choose the <tt>Mask</tt> tab to created a control for free handdraw of shapes on each slice. It will appear as a small icon on the toolbar (see figure below). Secondary click on a drawn level will offer a menu of options, like interpolating between user-marked levels, or converting the current set of lines into a file.
 +
 
 +
The example below shows the process of constructing a mask tight on just three subunits a barrel-shaped protein. The "staves" will slightly twist, so that one shouldn't set a large space between the sections were the user actually draws points, otherwise the interpolation will fail.
  
 
[[File:mask_handdraw_montage.png|thumb|center|300px| The blue square is the control for the handdrawn shape. Solid red are levels interpolated between the user-drawn light levels]]
 
[[File:mask_handdraw_montage.png|thumb|center|300px| The blue square is the control for the handdrawn shape. Solid red are levels interpolated between the user-drawn light levels]]
Line 35: Line 43:
 
== By thresholding and smoothing==
 
== By thresholding and smoothing==
  
A mask can be defined to XXXXX
+
A mask can be defined by thresholding the intensity of a given template.
 +
 
 +
Assuming a template where protein is dark on a bright background:
 +
 
 +
Creates a variable in the workspace that contains the template
 +
 
 +
<tt> template = dread('template.em'); % reads the file</tt>
  
 +
Create an all black cube:
  
 +
<tt> mask = zeros(size(template)); </tt>
 +
 +
puts ones (mask is bright) on the pixels where the template has lowest values, in this case below a predefined template:
 +
 +
<tt> threshold = -0.003; </tt>
 +
<tt> mask(find(template<threshold))=1;  </tt>
 +
 +
[[File: template_for_mask_creation_by_thresholding.png|thumb|center|300px| Phantom volume]]
 +
 +
[[File: mask_created_by_thresholding.png|thumb|center|300px| Created mask]]
 +
 +
 +
This procedure frequently needs some auxiliary steps like:
 +
# visualizing the density map of the template to select an appropriate threshold
 +
# using bandpass/median filters before the thresholding operation
 +
# using dilation operations on the created mask
 +
# intersecting the density-based map with a wider geometrical mask.
  
 
== Combination of masks ==
 
== Combination of masks ==
Line 43: Line 75:
 
It is easy to create combinations of masks using logical operators: {{t|or}} just "adds" masks.  
 
It is easy to create combinations of masks using logical operators: {{t|or}} just "adds" masks.  
  
Alternatively, you can use the compact syntax in {{t|dynamo_mask_combine}} on a cell array of masks defined independently. The flag {{t|delete}} can be used to define parts of the final mask that need to be set to zero (black).
+
Alternatively, you can use the compact syntax in {{t|dynamo_mask_combine}} on a cell array of masks defined independently.  
 +
 
 +
  <nowiki>% adds two different masks
 +
a{1} = dynamo_sphere(20,128,[64,64,40]);
 +
a{2} = dynamo_sphere(20,128,[64,64,80]);
 +
finalMask = dynamo_mask_combine(a);
 +
dview(finalMask)</nowiki>
 +
 
 +
The flag {{t|delete}} can be used to define parts of the final mask that need to be set to zero (black).
  
 +
<nowiki> % deletion
 +
a = dynamo_sphere(60,128);
 +
b = dynamo_sphere(20,128);
 +
% deletes mask b from mask a
 +
finalMaskWithoutCenter = dynamo_mask_combine(a,'delete',b);
 +
dview(finalMaskWithoutCenter)</nowiki>
  
 
== Depicting mask overlays ==
 
== Depicting mask overlays ==
Line 57: Line 103:
 
{{t|ov}} or {{t|overlay}} is the overlaying volume (in this case the just created file {{t|mask.em}}), {{t|ovas}} or {{t|overlay_as}} indicates that the overlaying volume is to be understood as a solid mask (i.e., we are interested in showing the bright pixels in the mask as a solid color). You can choose color and transparency with {{t|ovc}}/{{t|overlay_color}} and {{t| alpha}}.
 
{{t|ov}} or {{t|overlay}} is the overlaying volume (in this case the just created file {{t|mask.em}}), {{t|ovas}} or {{t|overlay_as}} indicates that the overlaying volume is to be understood as a solid mask (i.e., we are interested in showing the bright pixels in the mask as a solid color). You can choose color and transparency with {{t|ovc}}/{{t|overlay_color}} and {{t| alpha}}.
  
[[File:overlayed_mask_dslices.png|thumb|center|300px| Mask overlay with {{t|dslices}}]]
+
[[File:overlayed_mask_dslices.png|thumb|center|500px| Mask overlay with {{t|dslices}}]]

Latest revision as of 10:58, 14 September 2017

Dynamo uses several types of masks in different pipelines.

Masks are used in Dynamo for several purposes: indicating the active part of the template for alignment, restricting the area of the aligned particles that will count for classification, avoiding FSC artifacts, placing aligned averages back in a tomogram....

In some tasks, the masks are expected to be simple geometrical shapes. In other occasions, it might be necessary to have a finer control on the process of constructing a mask. Dynamo includes several tools:

Geometrical Shapes

Use dmask to open a GUI with several geometrical options: spheres, ellipsoids, tubes, cylinders. dmask can be used from the command line.

There are other commands for specific geometries: dsphere, dshell, dcylinder....

Freehand draw

You can edit a template and draw on its 2D slices handdraw lines each enclosing an area of interest. There a different ways to convert such an area into a 3d volume

Revolution solids

Here, you would enclose an area on a 2d slice that includes the Z axis (i.e., a section from an X-view or a Z-view), and then let Dynamo rotate the area around the central Z axis to create a revolution solid.

This can be done with dynamo_mapview. Open your template, go to an X view, select one slice and press on [shift+S]. A second window will pop up, zooming into the selected slice. When you finish, the message area will tell you the name of the file containing the the created revolution solid, by default temp_drawn_revolution_mask.em. You can secondary click on it to directly show in Chimera.

Select a central section representing an x-view and click shift+S
Draw the line and click secondary click to close the line
Revolution solid, visualized in Chimera

Slide by slide

You can edit a volume as a montage of orthoslices, and handdraw on each of them, or onto a selection of them an let Dynamo interpolate on the other sections. This interpolation is purely geometrical and doesn't take the graymap into account.

You can test the procedure with the shipped phantom template.

dpkvol.montage('template.em');

Then choose the Mask tab to created a control for free handdraw of shapes on each slice. It will appear as a small icon on the toolbar (see figure below). Secondary click on a drawn level will offer a menu of options, like interpolating between user-marked levels, or converting the current set of lines into a file.

The example below shows the process of constructing a mask tight on just three subunits a barrel-shaped protein. The "staves" will slightly twist, so that one shouldn't set a large space between the sections were the user actually draws points, otherwise the interpolation will fail.

The blue square is the control for the handdrawn shape. Solid red are levels interpolated between the user-drawn light levels

By thresholding and smoothing

A mask can be defined by thresholding the intensity of a given template.

Assuming a template where protein is dark on a bright background:

Creates a variable in the workspace that contains the template

template = dread('template.em'); % reads the file

Create an all black cube:

mask = zeros(size(template));

puts ones (mask is bright) on the pixels where the template has lowest values, in this case below a predefined template:

threshold = -0.003; mask(find(template<threshold))=1;

Phantom volume
Created mask


This procedure frequently needs some auxiliary steps like:

  1. visualizing the density map of the template to select an appropriate threshold
  2. using bandpass/median filters before the thresholding operation
  3. using dilation operations on the created mask
  4. intersecting the density-based map with a wider geometrical mask.

Combination of masks

It is easy to create combinations of masks using logical operators: or just "adds" masks.

Alternatively, you can use the compact syntax in dynamo_mask_combine on a cell array of masks defined independently.

  % adds two different masks
a{1} = dynamo_sphere(20,128,[64,64,40]);
a{2} = dynamo_sphere(20,128,[64,64,80]);
finalMask = dynamo_mask_combine(a);
dview(finalMask)

The flag delete can be used to define parts of the final mask that need to be set to zero (black).

 % deletion 
a = dynamo_sphere(60,128);
b = dynamo_sphere(20,128);
% deletes mask b from mask a
finalMaskWithoutCenter = dynamo_mask_combine(a,'delete',b);
dview(finalMaskWithoutCenter)

Depicting mask overlays

When you design a mask, it is frequently useful to check how it relates to a given template. This can be done with the command dslices, using the flags overlay, overlay_as

For instance, if you have a template template.em and want to see how a sphere of radius=16 would act on it, you can type:

dwrite(dynamo_sphere(16,64),'mask.em');
dslices template.em y -ov mask.em -ovas mask -ovc b

ov or overlay is the overlaying volume (in this case the just created file mask.em), ovas or overlay_as indicates that the overlaying volume is to be understood as a solid mask (i.e., we are interested in showing the bright pixels in the mask as a solid color). You can choose color and transparency with ovc/overlay_color and alpha.

Mask overlay with dslices