timothygrant80 / cisTEM

Other
32 stars 25 forks source link

Artifacts in match_template output after setting defocus search #508

Open mgiammar opened 2 months ago

mgiammar commented 2 months ago

After setting a defocus search range in the match_template program the resulting outputs show some odd line-like artifacting for the locations of identified particles. Here are what the results look like from the GUI

scaled_mip plotted_result

What's odd is the template match runs fine before setting a defocus search range, but once a defocus search range has been set for a template matching run this artifacting behavior persists for all future runs. Particle symmetry does not seem to have any affect on the outputs.

The unscaled MIP, correlation mean and variance outputs along with the best orientation angles show similar issues so I'm suspecting that the issue lies somewhere in the cross correlation step.

bHimes commented 2 months ago

Here are a few items that may help us troubleshoot:

please grab another screen cap of the same output, but switch the tab to the image not the mip, and click the "show job details" please.

Also, please show the corresponding search result without the defocus search. (with the mip as you have here, but adding the "show job details)

And finally, please show a view through a slice or projection of your template, as well as letting us know the x,y,z dimensions.

mgiammar commented 2 months ago

I'm having some permission issues when opening the .db file with the cisTEM program. The above screen captures were generated by another user; I can have them produce the requested screen captures later. I can, however, open the database file and jobs 286 and 287 complete normally (give reasonable outputs), but everything past job 288 (when defocus search was included) has similar artifacting issues. Sorry for the shoddily formatted info; it's the best I can do right now.

TEMPLATE_MATCH_ID   JOB_NAME                        DATETIME_OF_RUN     TEMPLATE_MATCH_JOB_ID   JOB_TYPE_CODE   INPUT_TEMPLATE_MATCH_ID     IMAGE_ASSET_ID      REFERENCE_VOLUME_ASSET_ID   IS_ACTIVE   USED_SYMMETRY   USED_PIXEL_SIZE     USED_VOLTAGE    USED_SPHERICAL_ABERRATION   USED_AMPLITUDE_CONTRAST     USED_DEFOCUS1   USED_DEFOCUS2   USED_DEFOCUS_ANGLE  USED_PHASE_SHIFT    LOW_RESOLUTION_LIMIT    HIGH_RESOLUTION_LIMIT   OUT_OF_PLANE_ANGULAR_STEP   IN_PLANE_ANGULAR_STEP   DEFOCUS_SEARCH_RANGE    DEFOCUS_STEP    PIXEL_SIZE_SEARCH_RANGE     PIXEL_SIZE_STEP     REFINEMENT_THRESHOLD    USED_THRESHOLD      REF_BOX_SIZE_IN_ANGSTROMS   MASK_RADIUS     MIN_PEAK_RADIUS     XY_CHANGE_THRESHOLD EXCLUDE_ABOVE_XY_THRESHOLD
286                 Full search with mtorc1_7uxh    1487356110          6                       0               -1                          168                 8                           1           C2              1.54                300.0           2.7                         0.07                        11684.99707     11374.800781    11.998374           0.0                 300.0                   3.08                    2.5                         1.5                     0.0                     0.0             0.0                         0.0                 0.0                     7.388458            416.0                       0.0             10.0                0.0                 0
287                 Full search with mtorc1_7uxh    1487356110          6                       0               -1                          171                 8                           1           C2              1.54                300.0           2.7                         0.07                        12561.710938    12415.720703    44.386658           0.0                 300.0                   3.08                    2.5                         1.5                     0.0                     0.0             0.0                         0.0                 0.0                     7.388458            416.0                       0.0             10.0                0.0                 0
288                 Full search with mtorc1_7uxh    1487570788          7                       0               -1                          18                  8                           0           C2              1.54                300.0           2.7                         0.07                        10860.828125    11060.197266    89.643349           0.0                 300.0                   3.08                    2.5                         1.5                     1200.0                  200.0           0.0                         0.0                 0.0                     7.722284            416.0                       0.0             10.0                0.0                 0
289                 Full search with mtorc1_7uxh    1487570788          7                       0               -1                          98                  8                           0           C2              1.54                300.0           2.7                         0.07                        7002.06543      6589.306641     44.371067           0.0                 300.0                   3.08                    2.5                         1.5                     1200.0                  200.0           0.0                         0.0                 0.0                     7.722284            416.0                       0.0             10.0                0.0                 0
290                 Full search with mtorc1_7uxh    1487813903          8                       0               -1                          18                  8                           1           C1              1.54                300.0           2.7                         0.07                        10860.828125    11060.197266    89.643349           0.0                 300.0                   3.08                    2.5                         1.5                     1200.0                  200.0           0.0                         0.0                 0.0                     7.809365            416.0                       0.0             10.0                0.0                 0
291                 Full search with mtorc1_7uxh    1487813903          8                       0               -1                          98                  8                           1           C1              1.54                300.0           2.7                         0.07                        7002.06543      6589.306641     44.371067           0.0                 300.0                   3.08                    2.5                         1.5                     1200.0                  200.0           0.0                         0.0                 0.0                     7.809365            416.0                       0.0             10.0                0.0                 0
292                 Full search with clathrin_6wcj  1487879371          9                       0               -1                          137                 9                           0           C1              1.54                300.0           2.7                         0.07                        14048.013672    14467.306641    -41.796566          0.0                 300.0                   3.08                    2.5                         1.5                     0.0                     0.0             0.0                         0.0                 0.0                     7.4793              360.0                       0.0             10.0                0.0                 0
293                 Full search with clathrin_6wcj  1487880736          10                      0               -1                          137                 9                           1           C1              1.54                300.0           2.7                         0.07                        14048.013672    14467.306641    -41.796566          0.0                 300.0                   3.08                    2.5                         1.5                     0.0                     0.0             0.0                         0.0                 0.0                     7.4793              360.0                       0.0             10.0                0.0                 0

I've also tested the cli version of match_template both with and without the defocus search and the artifacting issues does not present itself there both before and after setting the defocus search. Since the cli interface of match_template is working fine so I suspect it has something to do with reading the SQL db.

mgiammar commented 2 months ago

Also this is using CiSTEM version 2.0.0-alpha- 151-d42312b-dirty

rezaparaanczi commented 2 months ago

Here are the requested screenshots, after the first time this issue appeared all the subsequent jobs were affected regardless of defocus search: Screenshot 2024-06-10 at 1 17 37 PM

rezaparaanczi commented 2 months ago

Screenshot 2024-06-10 at 1 21 01 PM

rezaparaanczi commented 2 months ago

This is the job where it all started: Screenshot 2024-06-10 at 1 14 47 PM Screenshot 2024-06-10 at 1 15 01 PM

bHimes commented 1 month ago

Sorry for the lag there, I've had some personal things that required most of my spare brain space the last couple of weeks.

Thank you for the extra information about the database @mgiammar. All the values look fine, but your observation that the CLI works fine and that the bug persists in the GUI after turning off the defocus sweep is very interesting. Thanks also for the specific version, that will help with further trouble shooting.

So there are two things to discuss. The observed bug, and the nature of your project. I'll separate these two.

Bug discussion

We have a few good symptoms to look at, so I think the next step will to be reproducibility on our end. @rezaparaanczi Please put together a compressed folder with the following that you can share via your preferred method.

Sample may not be suitable for current implementation of TM in cisTEM

Clatherin! Let me start with a bit of a disclaimer: Putting this apparent bug aside for a moment, you are working with a sample that is really going to test the limits of the current implementation of template matching.

1 - the odd shape produces an orientation-dependent distribution of SNR values, which violates the underlying statistical hypothesis that comparing one noisy image to each of N independent orientations produces a distribution of SNR values similar to comparing one orientation to N independent noisy images.

Finding a good solution to this is an active area of research, and I think it would be worth asking @timothygrant80 for a brief comment on whether he thinks your project is feasible currently.

2 - adding in a target environment that has dramatic differences in the local image variance further violates our current assumption that the noise in the image is stationary. We currently deal with this via "flat-fielding" the pixel wise mean and variance after the search. The problem is that with something shaped like clatherin, the statistical images we record for this process only tell us the first two moments of the underlying distribution. This is fine for a normal distribution, but for the triskelion shape, the pixel-wise distribution of SNR values is decided not Gaussian.

bHimes commented 1 month ago

@twagner9 I am not sure this has to do with the defocus sweep or if that is just a coincidence and something else is broken in the DB. Can you have a read over this issue and see if it is something you would be interested in taking a look at once the repro data are shared?

twagner9 commented 1 month ago

@twagner9 I am not sure this has to do with the defocus sweep or if that is just a coincidence and something else is broken in the DB. Can you have a read over this issue and see if it is something you would be interested in taking a look at once the repro data are shared?

@bHimes Yes, I'd be happy have a look at this once the sample data is available.

rezaparaanczi commented 1 month ago

Hi Ben,

Thank you so much for the feedback. I have shared a sample micrograph here with a template of mtorc1. Hope this helps. Best regards, Reza debugging.zip https://drive.google.com/file/d/1vrXkdowPmxpinEOVoXxqX0KTQ_s23dWo/view?usp=drive_web

On Sat, Jun 29, 2024 at 4:47 AM B.A.Himes @.***> wrote:

Sorry for the lag there, I've had some personal things that required most of my spare brain space the last couple of weeks.

Thank you for the extra information about the database @mgiammar https://github.com/mgiammar. All the values look fine, but your observation that the CLI works fine and that the bug persists in the GUI after turning off the defocus sweep is very interesting. Thanks also for the specific version, that will help with further trouble shooting.

So there are two things to discuss. The observed bug, and the nature of your project. I'll separate these two.

Bug discussion

We have a few good symptoms to look at, so I think the next step will to be reproducibility on our end. @rezaparaanczi https://github.com/rezaparaanczi Please put together a compressed folder with the following that you can share via your preferred method.

  • The template used when encountering the error
  • One micrograph where the error occured
  • A text file with the imaging parameters needed to create a new project (imaging parameters)

Sample may not be suitable for current implementation of TM in cisTEM

Clatherin! Let me start with a bit of a disclaimer: Putting this apparent bug aside for a moment, you are working with a sample that is really going to test the limits of the current implementation of template matching.

1 - the odd shape produces an orientation-dependent distribution of SNR values, which violates the underlying statistical hypothesis that comparing one noisy image to each of N independent orientations produces a distribution of SNR values similar to comparing one orientation to N independent noisy images.

Finding a good solution to this is an active area of research, and I think it would be worth asking @timothygrant80 https://github.com/timothygrant80 for a brief comment on whether he thinks your project is feasible currently.

2 - adding in a target environment that has dramatic differences in the local image variance further violates our current assumption that the noise in the image is stationary. We currently deal with this via "flat-fielding" the pixel wise mean and variance after the search. The problem is that with something shaped like clatherin, the statistical images we record for this process only tell us the first two moments of the underlying distribution. This is fine for a normal distribution, but for the triskelion shape, the pixel-wise distribution of SNR values is decided not Gaussian.

— Reply to this email directly, view it on GitHub https://github.com/timothygrant80/cisTEM/issues/508#issuecomment-2198123127, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBR5VDAAEKQJ5X3QWO67WZ3ZJ2NF5AVCNFSM6AAAAABI5INGWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGEZDGMJSG4 . You are receiving this because you were mentioned.Message ID: @.***>