GuignardLab / napari-manual-registration

BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

translation works but not rotation #3

Open xuefan007 opened 1 month ago

xuefan007 commented 1 month ago

Dear developer,

Thanks for the plug-in! This sounds really helpful for 3D image analysis. I shortly tried this plugin with multiple rounds ISS data for registration in napari (dot signal in 3D tissue). It works but have a problem: Translation function works (with all x,y,z), but Rotation not work. No response with image with what ever value that been put in. This gives no error message.

I have another question related to the usage, will this plugin work for sample that have slicely change in shape? (ie.z slice have 5% difference between 2 registrated rounds). Thanks a lot!

Best wishes, Xuefan

jules-vanaret commented 1 month ago

Hi @xuefan007, thank you very much for your feedback.

For you first question, my guess is that there is an issue with the pyclesperanto_prototype library that we use to rotate the arrays through the .rotate function. Could you try to run the following python snippet and tell me the output:

import numpy as np
import pyclesperanto_prototype as cle

a = np.random.rand(10,10,10)
print(cle.rotate(
    source=a,
    angle_around_z_in_degrees=10,
    angle_around_y_in_degrees=10,
    angle_around_x_in_degrees=10,
    rotate_around_center=True,
    linear_interpolation=False,
    auto_size=False
))

If the function does display the expected result, then this might just be due to the fact that the data you are using is too voluminous, so much that the .rotate function effectively takes a huge amount of time to return. Could you tell me the shape (number of pixels in each dimension) of the data you are trying to register ?

For your second question, I am not sure I fully understand. Are you asking if it is possible to load two views ("floating" and "reference" in the plugin) that have different voxel sizes (i.e the spacing in z has a 5% difference between the two views) ?

xuefan007 commented 1 month ago

Hi @jules-vanaret,

Thanks so much for your kind reply. I am sorry for the late reply since I was out of lab for 1 week.

I run your testing code, it seems do has problem with cle: "RecommendedHashNotFoundWarning: Unable to import recommended hash 'siphash24.siphash13', falling back to 'hashlib.sha256'. Run 'python3 -m pip install siphash24' to install the recommended hash." I went further to update cle and then run the test cod, but this time got "clGetPlatformIDs failed: PLATFORM_NOT_FOUND_KHR" warn("Unable to import recommended hash 'siphash24.siphash13', " And the plug-in can not open in napari as well. Are there specific requirements of the plug-in to run? ie. certein version of python and other soft etc.?

The plug-in was working for 2D for both translation and rotation. Only has problem with 3D data. The data size i am trying now is for testing: roughfly 800 x 800 pix, with 80 slices. About 100 mb.

For the last question, it is indeed as you understood. I am asking if it is possible to load two views ("floating" and "reference" in the plugin) that have different voxel sizes (i.e the spacing in z has a 5% difference between the two views) ?

Thanks to much!

jules-vanaret commented 1 month ago

Hi @xuefan007 , no problem! The documentation from the pyclesperanto_prototype library (here) suggests that this is an issue with the drivers on your machine, and provides some instructions to fix the issue. Perhaps, this Github discussion could be useful too. I have never had this issue on linux, are you on windows ?

By the way, do you have a GPU on your computer ? If not, running pyclesperanto_prototype on CPUs is explained here. The installation is easier, but the rotations will be much slower for 3D data. Note that depending on your final use of the transformations, you might want to downscale your image, which will make CPU rotations run faster.

For your second question, I guess if the two views don't have the same voxel size, the problem is slightly ill posed... In practice, it depends on the level of precision you want to achieve. From the napari interface, you can change the "display voxel size" by clicking on the bottom left-most button which looks like ">_". Then type viewer.layers['NAME_OF_LAYER'].scale = [voxelsize_z,voxelsize_y,voxelsize_x], e.g viewer.layers['floating_data'].scale = [1.05,1,1] and press enter. This will stretch the floating layer (or the reference layer if you have specified its name instead) according to the scaling factors you provide. Thus, the two views will appear to have the same voxelsize. The only problem is the transformations you will obtain are only valid in the space of the layer which has not been rescaled, so it depends on what you want to do with the transformations after.

I hope this helped you, feel free to reach out if you need!

xuefan007 commented 1 month ago

Hi @jules-vanaret,

Thanks for your kind answer! My mac has a Graphic card, ca. 4 GB. "AMD Radeon Pro 5300M Compute Engine on Platform: Apple (2 refs)". I am not sure whether it is big enough for our datasize (ie. 800x800 pix, 50 slice, 100-200 MB) with registration (rotation).

I checked the pyclesperanto_prototype library, and find out that my mac need to install this: "conda install -c conda-forge ocl_icd_wrapper_apple". The plug-in works again after the installation although the rotation still not working...

Your test code work like this: [[[0.3374059 0.7917488 0.24408156 0.54623604 0. 0.

        1. ] [0.9185042 0.5412872 0.8329506 0.2223796 0.21384609 0.44930068 0.47042438 0.27030239 0.9569956 0.76981515] [0.06509552 0.0774955 0.22710031 0.14484695 0.03538975 0.53457755 0.803794 0.27170265 0.7931686 0.26179114] [0. 0.8279122 0.9851189 0.08453761 0.3648576 0.8378696 0.82323587 0.9476486 0.04484856 0.00631668] [0. 0.09963079 0.52021873 0.7626861 0.65779096 0.89468896 0.5572844 0.7285749 0.6784178 0. ] [0. 0. 0.9481527 0.9063737 0.8137193 0.08888192 0.52111435 0.9094556 0.78954595 0. ] [0. 0. 0. 0.18771756 0.71049154 0.3976213 0.21427399 0.20130324 0.33686045 0. ] [0. 0. 0. 0. 0.29279184 0.37461624 0.85354644 0.6123506 0.1356413 0. ] [0. 0. 0. 0. 0.95465165 0.811678 0.8844986 0.90994954 0.02476094 0. ] [0. 0. 0. 0. 0. 0.6726433 0.995518 0.995518 0.6139825 0. ]]

    [[0.2754557 0.9708368 0.07435158 0.4157816 0.26321292 0.

        1. ] [0.11618227 0.4252662 0.20166601 0.11776724 0.13850541 0.31963697 0.17769025 0.6903004 0.76320416 0.76981515] [0.8704382 0.683545 0.79836285 0.7643536 0.3111021 0.43616238 0.31324854 0.1452466 0.73530084 0.6353628 ] [0.73026806 0.8140511 0.26321122 0.78516716 0.4342186 0.77485013 0.54445684 0.828281 0.88131577 0.11255108] [0.65038335 0.09963079 0.10099654 0.89477223 0.9630209 0.12302154 0.12302154 0.49608016 0.25771308 0.73897916] [0.5570722 0.90108514 0.0410331 0.47927126 0.06695578 0.5892836 0.28491864 0.03335746 0.6519469 0. ] [0.9897106 0.19479719 0.6111328 0.21571934 0.36791486 0.3771638 0.15702572 0.5848552 0.57893866 0. ] [0.00162491 0.42647487 0.557453 0.20719293 0.4248191 0.9406725 0.08500686 0.10307416 0.53670937 0. ] [0.6923166 0.29646155 0.3809781 0.02134487 0.7419793 0.38905004 0.35900068 0.29915655 0.70734936 0. ] [0.53239024 0.53239024 0.01084329 0.7561822 0.6394183 0.33869687 0.5307012 0.33557984 0.66813064 0. ]]

    [[0.00958189 0.79772276 0.52357405 0.3686382 0.20200828 0.03506562

        1. ] [0.45213574 0.67120147 0.51008904 0.42663953 0.13850541 0.6505735 0.72091335 0.7684428 0.46090952 0.3418861 ] [0.19655322 0.51192516 0.4988574 0.07691546 0.37489465 0.75945395 0.49285445 0.7974858 0.8313478 0.09358973] [0.78435266 0.690885 0.3714199 0.48081964 0.0168154 0.6761556 0.07009643 0.52373904 0.6835814 0.33305344] [0.23736817 0.9853152 0.3521037 0.0304453 0.2647967 0.54560196 0.9717093 0.5640149 0.4817422 0.7750183 ] [0.00390752 0.7861294 0.23562145 0.31497338 0.2625141 0.46435958 0.46435958 0.48908314 0.73133105 0.26867417] [0.84934235 0.94759995 0.41623518 0.54770535 0.77976024 0.73834985 0.2544858 0.26959512 0.13918705 0. ] [0.27623594 0.3076165 0.5163953 0.20372392 0.32030636 0.34659874 0.36811432 0.3388297 0.19042666 0. ] [0.6231675 0.6875644 0.6571307 0.5272093 0.19188657 0.58847123 0.0853912 0.59053886 0.27715087 0. ] [0.4364813 0.0410571 0.34582782 0.15892987 0.26744238 0.80913335 0.33355874 0.15585972 0.14741436 0. ]]

    [[0.2921571 0.69632626 0.12525362 0.7764522 0.01523705 0.01523705 0.82919115 0.6232141 0. 0. ] [0.6830292 0.5415521 0.83017534 0.6228455 0.01456914 0.58197486 0.92919946 0.43575644 0.6846115 0.32440343] [0.7717739 0.31003547 0.77393496 0.85352296 0.3841372 0.75945395 0.9032312 0.49166137 0.49015394 0.12394965] [0.5590166 0.16308635 0.40988114 0.17875488 0.450084 0.95815927 0.5467036 0.20611289 0.24459083 0.96138734] [0.27045044 0.11315141 0.13503958 0.8068373 0.07329934 0.34762445 0.5683106 0.16426535 0.28327522 0.29801065] [0.11694891 0.48786715 0.07063696 0.0212147 0.1737316 0.7794136 0.9049564 0.48908314 0.46348906 0.78142077] [0.14353359 0.92647356 0.71409035 0.6586998 0.09615532 0.87703437 0.9049564 0.426868 0.40402317 0.7014887 ] [0.54973966 0.08671722 0.61539906 0.620504 0.17037703 0.46063748 0.53693587 0.7771055 0.30534738 0. ] [0.29392377 0.12375564 0.51060134 0.68126184 0.57167524 0.720936 0.7278521 0.9651633 0.84212005 0. ] [0.7415685 0.67094254 0.42931315 0.19394736 0.61303985 0.29074985 0.6285459 0.40337962 0.6017712 0. ]]

    [[0. 0.9177957 0.9538997 0.2631117 0.17347999 0.05110151 0.03093102 0.72183836 0.9590739 0. ] [0.32410735 0.7449259 0.34290108 0.7489263 0.0869622 0.37411365 0.5062157 0.39492434 0.9726364 0.6271976 ] [0.461004 0.01307633 0.22573252 0.66457087 0.7382759 0.53350955 0.8650898 0.66760105 0.11093961 0.43079168] [0.27197766 0.73178 0.8939808 0.85229844 0.8504212 0.5708049 0.02669447 0.55165917 0.5941928 0.6206745 ] [0.821083 0.01022789 0.05378307 0.07033191 0.1285893 0.8713538 0.32764 0.96254957 0.07901157 0.38192508] [0.23962794 0.08572955 0.7266952 0.10416301 0.11185192 0.74814296 0.31667903 0.9857237 0.80587953 0.18272619] [0.31425783 0.33325183 0.93191427 0.8762275 0.29817143 0.994367 0.96399075 0.02804761 0.40402317 0.0638497 ] [0.46321282 0.48529845 0.38808057 0.73637843 0.37761486 0.37761486 0.7095855 0.02804761 0.4547095 0.47482154] [0.33259568 0.05090918 0.5410214 0.6685789 0.11361855 0.33595118 0.54721767 0.50082594 0.7979698 0. ] [0.7415685 0.11538272 0.2764007 0.73149383 0.18882087 0.29074985 0.24566747 0.7526396 0.01914732 0. ]]

    [[0. 0.87111014 0.0383596 0.5882777 0.17028621 0.40024722 0.9117573 0.39946502 0.30223113 0.8680779 ] [0. 0.3533186 0.99118876 0.65785575 0.7992212 0.36317644 0.777865 0.8132688 0.654399 0.95646316] [0.9473951 0.24353743 0.36940724 0.4538903 0.80594236 0.80594236 0.7047748 0.43720296 0.39823452 0.35493907] [0.3702049 0.7119744 0.36940724 0.25482446 0.13254598 0.32558772 0.02669447 0.45869637 0.2514618 0.93119276] [0.60291356 0.12087722 0.90983915 0.4326675 0.27277747 0.11294968 0.49885774 0.17007042 0.23438598 0.89762914] [0.87008876 0.27675715 0.58212334 0.93465686 0.36384404 0.52527606 0.19190316 0.7683846 0.75091743 0.8758818 ] [0.0246936 0.74089235 0.48327866 0.8762275 0.8616722 0.5102143 0.08570196 0.677632 0.6969868 0.300539 ] [0.46391472 0.93323773 0.9205823 0.5065815 0.6516461 0.90147597 0.9236309 0.743994 0.18439144 0.7166785 ] [0.98085 0.12255587 0.99373317 0.04803995 0.06977182 0.88620526 0.7087772 0.9490928 0.03644806 0.58558863] [0. 0.29413745 0.29847664 0.8543051 0.37524435 0.26430333 0.956221 0.5883605 0.9554498 0. ]]

    [[0. 0.7708371 0.31719586 0.54560775 0.17028621 0.49916053 0.68136734 0.5398927 0.38044304 0.8680779 ] [0. 0.25276574 0.763001 0.06876289 0.6205828 0.43500328 0.7525529 0.72792464 0.30710548 0.99452883] [0. 0.48473462 0.4150974 0.18637438 0.14430353 0.822197 0.859236 0.06562449 0.91766346 0.9930153 ] [0.48600957 0.7119744 0.23605259 0.24384542 0.11372555 0.73166543 0.30684075 0.10407918 0.19223149 0.8490114 ] [0.39832246 0.41221708 0.22752115 0.24384542 0.2991357 0.58445364 0.81291145 0.6880099 0.82925016 0.19594 ] [0.5798434 0.4867895 0.12012278 0.02316628 0.69897157 0.12712157 0.13088833 0.8765782 0.48642004 0.23827955] [0.5547924 0.06453689 0.46237472 0.53543204 0.1214748 0.17044419 0.12110516 0.7889067 0.8217605 0.16022292] [0.17598344 0.5738746 0.45892677 0.03816772 0.25091323 0.81861424 0.9799038 0.69430184 0.07797527 0.6331668 ] [0.37814695 0.44273508 0.3134425 0.6440964 0.9546767 0.66478926 0.25284094 0.28131035 0.892909 0.37561864] [0. 0. 0.50710547 0.9471457 0.8859034 0.8859034 0.15164417 0.8640264 0.44351402 0.3422311 ]]

    [[0. 0.6151355 0.8990203 0.9875156 0.37386614 0.73095345 0.8967576 0.08579088 0.57855076 0.5429991 ] [0. 0.7868222 0.5842041 0.44716674 0.63982856 0.8161307 0.3967101 0.1660674 0.7791007 0.25764218] [0. 0.18881238 0.9579955 0.22650008 0.69529295 0.8035512 0.1947557 0.7623992 0.4614873 0.11303084] [0. 0.46068856 0.59204656 0.79890263 0.19767837 0.8004151 0.30999628 0.7589089 0.75316656 0.38451588] [0.87789494 0.14288126 0.22752115 0.7125323 0.7125323 0.3497641 0.15465471 0.12016296 0.34963256 0.20159139] [0.17185849 0.61259663 0.1491122 0.42805302 0.9671983 0.15797853 0.03869787 0.8738542 0.8384828 0.79413587] [0.52543056 0.30490422 0.60482585 0.24051215 0.18235955 0.7211077 0.10345302 0.9232004 0.20429799 0.6633394 ] [0.17025551 0.14034979 0.15466262 0.46426857 0.25091323 0.5077285 0.12675755 0.39080152 0.39204738 0.7907561 ] [0.1060768 0.0029523 0.06601277 0.2671066 0.60507303 0.55331933 0.48909757 0.38676283 0.72028166 0.6930321 ] [0. 0. 0. 0. 0.8277408 0.32125515 0.25090718 0.21788192 0.90036887 0.6999494 ]]

    [[0. 0.79766655 0.7470136 0.79727787 0.81690913 0.7725162 0.8364196 0.7221805 0.62928617 0.62928617] [0. 0.6789835 0.87921506 0.64720017 0.00982855 0.94049954 0.54922223 0.31481668 0.1229382 0.8365327 ] [0. 0.30484185 0.23846962 0.6641168 0.44123647 0.5222332 0.39253744 0.16164146 0.31302172 0.73745286] [0. 0.4979008 0.4026696 0.48398617 0.98873836 0.7956864 0.8267052 0.1494588 0.44384915 0.29899573] [0. 0.2234795 0.0345204 0.5230867 0.23742613 0.56798387 0.32438853 0.88173616 0.41387904 0.01388002] [0.0153958 0.87129235 0.5437956 0.6517082 0.6517082 0.64265335 0.31094778 0.22748874 0.77169424 0.42115334] [0.05435964 0.8364948 0.6536042 0.12277187 0.08607617 0.27823344 0.66645145 0.27698922 0.3558575 0.44948527] [0.14121474 0.7258163 0.3588999 0.69157934 0.5658178 0.7069057 0.00313229 0.23048557 0.6287763 0.04508254] [0.97982424 0.8351114 0.40938428 0.6988888 0.8267603 0.55331933 0.6846433 0.42066067 0.9852246 0.5388372 ] [0. 0. 0. 0. 0. 0.9134217 0.3191551 0.99023104 0.7379982 0.00342177]]

    [[0. 0.16327406 0.28361428 0.28361428 0.48521662 0.

        1. ] [0. 0.5203846 0.24510586 0.94953775 0.5997451 0.42745125
        1. ] [0. 0.15384415 0.22687088 0.08393907 0.68798476 0.30171072
        1. ] [0. 0.8652989 0.9488189 0.15706614 0.8340634 0.69747645 0.4039457 0. 0. 0. ] [0. 0.68022764 0.6121788 0.63198525 0.950645 0.06364449 0.51643527 0.31959885 0. 0. ] [0. 0.6516136 0.57887876 0.5870033 0.03815358 0.17290199 0.99335825 0.8097269 0.77169424 0. ] [0.9657709 0.2948716 0.9163589 0.58681726 0.33333802 0.1876265 0.6444408 0.764909 0.19699211 0. ] [0.29487643 0.557096 0.77555025 0.8412188 0.1424665 0.9241843 0.21109878 0.580485 0.8509295 0.15115468] [0.97982424 0.72541744 0.5679434 0.21252151 0.2889793 0.72041285 0.05793051 0.03079642 0.593657 0.18175165] [0. 0. 0. 0. 0. 0. 0.18534936 0.5166505 0.44578552 0.84185547]]]

Looks correct? Then I have no idea how to twist it.

For the second question, thank you for the suggestion! Sounds like a handy fast solution!

jules-vanaret commented 1 month ago

Great @xuefan007 ! This means the library now runs on your computer ! Now to solve your issue with rotation still not giving any result in the plugin, could you try heavily downsampling your reference and floating data, e.g by a factor of 4 in all dimensions ? To downsample, if you want to stay in python, you can check scipy.ndimage.zoom. If you feel more comfortable with Fiji, you can go to Image > Scale… or Image > Adjust > Size… to resize your image. Otherwise, the tapenade library from which this plugin stems also comes with a napari plugin for preprocessing (napari-tapenade-processing), with a function "Change Layer voxelsize" to interpolate data to another shape.

By the way, thank you very much for taking the time to provide a detailed list of your computer's details. I don't have a lot of feedback from Mac users so this means a lot.

xuefan007 commented 1 month ago

Hi @jules-vanaret,

Glad to know! I do hope this communication helps both side. :)

I croped the image, plus downsized it, end up with a 80 x 80 pix, 10 slice image file (400 kb). Still the rotation function does not work at my mac. When it was 3 channels image, gives error "ValueError: too many values to unpack (expected 3)". Then I tired with only one channel, gives error "AttributeError: 'NoneType' object has no attribute 'data'" and "EmitLoopError Traceback (most recent call last)".
Will Linux more suit for this plugin? then I will try to find a way to work on the cluster. How about windows system so far from the user feedback?

Best, Xuefan

xuefan007 commented 1 month ago

Hi again,

I got the heavily downsized data (80x80 pix, 10 slice, 400kb file) worked with rotation function! This happend after installed tapenade (which you said the plugin stems). But the bigger file (800x800 pix, 100 mb file) still not work with rotation.

jules-vanaret commented 1 month ago

Hi @xuefan007, sorry for the late follow-up. I'm glad that you got it working for the downsized data. Do you confirm that it works in the GUI , i.e when moving the rotation slider on the plugin interface you see your 3D (downsized) data rotating on the viewer ? If yes, what is the typical time it takes from the moment you moved the slider to the moment you see the data rotating ? This could give an idea of the time it takes for your real-sized data to compute the rotation.

By the way, I see in that in one of your previous message you mention that you tried the plugin with multi-channel images. Right now the plugin is meant only for 3D data, and I have never tested it with multi-channel data, hence the errors you encountered... :sweat_smile: If you would be interested in such a feature and you have a little bit of time, that would really help if you could send me the full error traceback that you got in the two situations you tried

When it was 3 channels image, gives error "ValueError: too many values to unpack (expected 3)". Then I tired with only one channel, gives error "AttributeError: 'NoneType' object has no attribute 'data'" and "EmitLoopError Traceback (most recent call last)".

Best,