cerr / CERR

Matlab/Octave based platform for Radiological Research.
https://cerr.github.io/CERR/
GNU Lesser General Public License v2.1
191 stars 101 forks source link

Deformable registration #661

Closed MohHu closed 2 years ago

MohHu commented 3 years ago

Dear developer(s),

Good morning, I have been using deformable image registration applied in CERR, and It works and deforms scan from moving image image to base image. What I am working on is that I am trying to applied a CERR tool for DIR between the base and the moving CT of the patient to generate the displacement vector field (DVF) inside of the OARs on base image. However, when I use the DIR code on this link (''https://github.com/cerr/CERR/wiki/Deformable-Image-Registration-(DIR)''), the scan is deformed, but the structures are not.

I was wondering how I can deform the structure, and how I can extract the DVF for each OARs contour?

Thank you in advance for effort and I appreciate your help and your suggestion!

Yours sincerely

MohHu commented 2 years ago

Wit regard to previous post, I have been able to deform the structure. Therefore, I would like to Also I would like to extract the DVF for each OARs contour and override the density of the structure to a given value. I used this script for overriding the density of the structure : global planC;

strNum = 1; %Replace with structure # of interest

%Get associated scan array

scanNum = getStructureAssociatedScan(strNum,planC);

scan3M = getScanArray(scanNum,planC);

%Get structure mask

mask3M = getStrMask(strNum,planC);

%Replace values within mask with assigned densities

scan3M(mask3M) = density3M(mask3M);

However, I have this error:

Undefined function 'density3M' for input arguments of type 'logical'. Error in Untitled (line 19) scan3M(mask3M) = density3M(mask3M);

I was wonder how I can extract the DVF for each OARs contour and how I can overcome the issue of using above code.

Yours sincerely

adityaapte commented 2 years ago

1> Here is a code snippet to obtain a vector field after running the registration. planC contains the base image and planD the moving image.

deformS = planC{indexS.deform}(end);

% Get vector field
vf = get_vector_field(deformS,planD,movScanNum,planC,baseScanNum);

2> To reassign intensity:

scan3M(mask3M) = density3M(mask3M); assumes that you have sensity3M available. If you want an uniform value, try the following

val = 500;

scan3M(mask3M) = val;

On Tue, Oct 26, 2021 at 3:01 AM MohHu @.***> wrote:

Wit regard to previous post, I have been able to deform the structure. Therefore, I would like to Also I would like to extract the DVF for each OARs contour and override the density of the structure to a given value. I used this script for overriding the density of the structure : global planC;

strNum = 1; %Replace with structure # of interest

%Get associated scan array

scanNum = getStructureAssociatedScan(strNum,planC);

scan3M = getScanArray(scanNum,planC);

%Get structure mask

mask3M = getStrMask(strNum,planC);

%Replace values within mask with assigned densities

scan3M(mask3M) = density3M(mask3M);

However, I have this error:

Undefined function 'density3M' for input arguments of type 'logical'. Error in Untitled (line 19) scan3M(mask3M) = density3M(mask3M);

I was wonder how I can extract the DVF for each OARs contour and how I can overcome the issue of using above code.

Yours sincerely

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-951619797, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJBYUMWEZRGCOOI5T5CLUIZG23ANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

MohHu commented 2 years ago

Thank you very much for your help.

This has now been resolved for me.

With regard to vector field, whether DVF is for a specific structure or all scan. Actually, I am looking for DVF for a contoured structure.

With regard to reassigning intensity, I saved planC after reassigning intensity using ''click right----->save as. However, when I opened it with CERR GUI, the structure has intensity as before.

MohHu commented 2 years ago

Dear Dr. Aditya,

Sorry for bothering you,

With regard to vector field, after executing the code, I got dvf as 3D .mat file, but there is no indication of the x, y and z components. What I mean in which direction Plastimatch calculates DVF, for instance vector in anterior-posterior (AP) direction, left-right (LR) direction or superior-inferior direction.

Thank you in advance

adityaapte commented 2 years ago

The vector field corresponds to CERR image coordinates. x,y,z grid for the vector field in CERR image coordinates can be obtained as follows: [xBaseV,yBaseV,zBaseV] = getUniformScanXYZVals(planC{indexS.scan}(scanNum)); [xBase3M,yBase3M,zBase3M] = meshgrid(xBaseV,yBaseV,zBaseV);

On Sun, Nov 14, 2021 at 3:12 PM MohHu @.***> wrote:

Dear Dr. Aditya,

Sorry for bothering you,

With regard to vector field, after executing the code, I got dvf as 3D .mat file, but there is no indication of the x, y and z components. What I mean in which direction Plastimatch calculates DVF, for instance vector in anterior-posterior (AP) direction, left-right (LR) direction or superior-inferior direction.

Thank you in advance

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-968355900, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB2FZMQ5DLU6KKCITPDUMAJ4VANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

MohHu commented 2 years ago

Thank you very much

MohHu commented 2 years ago

Dear Sir,

Good morning,

I was wondering whether CERR has crop and resample function.

Yours sincerely

adityaapte commented 2 years ago

% Crop Scan within the bounding box of strNum strNum = 1; scanNum = 1; margin = 1.5; %cm, planC = cropScan(scanNum,strNum,margin,planC);

% Resample scan to a new resolution dx = 0.1; %cm, dy = 0.1; %cm, dz = 0.1; %cm, sinc_flag = 0; % set to 1 to use sinc sampling, 0 for linear interp. planC = reSliceScan(scanNum,dx,dy,dz,sinc_flag,planC);

In order to create a cubic ROI, type createROI in the CERR command box and follow the instructions to select bounds on any of the two views.

On Wed, Dec 22, 2021 at 10:04 AM MohHu @.***> wrote:

Dear Sir,

Good morning,

I was wondering whether CERR has crop and resample function.

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-999642073, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB2FQBIBXBIMUDCA5XLUSHSHZANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

MohHu commented 2 years ago

Thanks a lot for your prompt reply,

Resampling function works, but cropping function causes this following error. Also, when I type createROI in the CERR command box, I have pupup with these three options (''Rectangular''Free-hand''&''cancel''). I chose ''Rectangular'' option, but there is no furhter steps to complete the cropping

Index exceeds matrix dimensions. Error in getStructureAssociatedScan (line 65) assocScanUID = allAssocScanUID(structsV); Error in cropScan (line 66) assocScanNum = getStructureAssociatedScan(structureNum,planC);

Do you have a manual on how to conduct cropping?

Yours sincerely

adityaapte commented 2 years ago

To create a rectangular ROI, simply draw rectangles on any of the two views, then right click and hit "Create 3D ROI".

The cropScan function is producing errors since the structure input to it does not exist.

On Wed, Dec 22, 2021 at 2:03 PM MohHu @.***> wrote:

Thanks a lot for your prompt reply,

Resampling function works, but cropping function causes this following error. Also, when I type createROI in the CERR command box, I have pupup with these three options (''Rectangular''Free-hand''&''cancel''). I chose ''Rectangular'' option, but there is no furhter steps to complete the cropping

Index exceeds matrix dimensions. Error in getStructureAssociatedScan (line 65) assocScanUID = allAssocScanUID(structsV); Error in cropScan (line 66) assocScanNum = getStructureAssociatedScan(structureNum,planC);

Do you have a manual on how to conduct cropping?

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-999798950, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB3WFX7KCKJGAEJVTCDUSIOILANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

adityaapte commented 2 years ago

Here is the documentation for slice-wise contouring tool: https://github.com/cerr/CERR/wiki/Contouring-(using-reference-series)

Instructions for createROI command are missing. Would you like to create a pull request for this documentation? Thanks.

On Wed, Dec 22, 2021 at 6:36 PM Aditya Apte @.***> wrote:

To create a rectangular ROI, simply draw rectangles on any of the two views, then right click and hit "Create 3D ROI".

The cropScan function is producing errors since the structure input to it does not exist.

On Wed, Dec 22, 2021 at 2:03 PM MohHu @.***> wrote:

Thanks a lot for your prompt reply,

Resampling function works, but cropping function causes this following error. Also, when I type createROI in the CERR command box, I have pupup with these three options (''Rectangular''Free-hand''&''cancel''). I chose ''Rectangular'' option, but there is no furhter steps to complete the cropping

Index exceeds matrix dimensions. Error in getStructureAssociatedScan (line 65) assocScanUID = allAssocScanUID(structsV); Error in cropScan (line 66) assocScanNum = getStructureAssociatedScan(structureNum,planC);

Do you have a manual on how to conduct cropping?

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-999798950, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB3WFX7KCKJGAEJVTCDUSIOILANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

MohHu commented 2 years ago

Dear Dr. Aditya,

((''Would you like to create a pull request for this documentation?'')

I have two sets of images. Each set has different volume from another. I used these sets as an input into image registration code. Before registering them, I would like to crop them and make them of the same volume.

It is not clear to me how to crop the image. Why t does ''the cropScan function'' requires the structure input because I am working only with scan?

Yours sincerely

adityaapte commented 2 years ago

The cropScan function uses structure bounds to crop the image ( with a margin). So you will need to define a structure on each scan before cropping.

On Thu, Dec 23, 2021, 1:24 AM MohHu @.***> wrote:

Dear Dr. Aditya,

((''Would you like to create a pull request for this documentation?'')

I have two sets of images. Each set has different volume from another. I used these sets as an input into image registration code. Before registering them, I would like to crop them and make them of the same volume.

It is not clear to me how to crop the image. Why t does ''the cropScan function'' requires the structure input because I am working only with scan?

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-1000073043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB5X7EVPVNPK362LZJTUSK6ATANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

MohHu commented 2 years ago

Thank you.

It works, and I got what is required to my work. I have further question: 1- I have extracted DVF using the code that you already mentioned, then modified.

Could you tell me how I could deform the moving image with modified dvf?

Yours sincerely

MohHu commented 2 years ago

Dear developer, Is there any suggestion for last post? I also have further question to the last post.

Could you tell me where I can find rigid image registration results (as transformation matrix) from CERR?

Yours sincerely

adityaapte commented 2 years ago

The existing wrapper function to create deformed scan/structure/dose works from bspline coefficients. Here is suggestion to use vector field to warp image objects:

1> Create a function createMhaVectorFieldFromCERR.m using createMhaScansFromCERR.m as the template.

2> Use the following transformations to convert from CERR to mha coordinate system.

vfFileName = 'absolute/path/to/save/vector/field/file'; vf_mha_coords(:,:,:,1) = flipdim(permute(vf(:,:,:,1),[2,1,3]),3)10; vf_mha_coords(:,:,:,2) = flipdim(permute(-vf(:,:,:,2),[2,1,3]),3)10; vf_mha_coords(:,:,:,3) = flipdim(permute(-vf(:,:,:,3),[2,1,3]),3)*10;

3> Update warp_scan.m etc functions to handle vector field.

On Fri, Dec 24, 2021 at 5:22 PM MohHu @.***> wrote:

Thank you.

It works, and I got what is required to my work. I have further question: 1- I have extracted DVF using the code that you already mentioned, then modified.

Could you tell me how I could deform the moving image with modified dvf?

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-1000940770, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB5CFWLWCDQYXMXOXLDUSTXBLANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

MohHu commented 2 years ago

Dear Dr. adityaapte,

Good morning,

I am working on analyzing the difference between the results of CERR registration and the other registration. Actually, the observation check seems to be alright, but when I try to make quantitative analysis, there is a significant difference between two algorithms, which is not relevant to the real results.

The second algorithm that I use has this property (''DVF is specified per voxel, rather than using any physical coordinates. While the positive direction is along how voxel indices increase, the values in DVF are in the unit of voxels''.

Do you mind me asking if it is possible to modify the dvf measured up by CERR to the type mentioned above?

I appreciate your efforts.

Yours sincerely

adityaapte commented 2 years ago

According to what you described, the units of DVF resulting from your 2nd DVF algorithm are in voxels. "DVF is specified per voxel, rather than using any physical coordinates. While the positive direction is along how voxel indices increase, the values in DVF are in the unit of voxels."

The DVF calculated in CERR (using plastimatch) is in physical units (cm per CERR units). So you will have to convert DVFs to the same units. Here is how you can convert the 2nd DVF to physical units:

global planC indexS = planC{end}; scanNum = 1; [xV,yV,zV] = getScanXYZVals(planC{indexS.scan}(scanNum)); dx = abs(xV(1) - xV(2)); dy = abs(yV(1) - yV(2)); dz = abs(zV(1) - zV(2)); xDVF_cm = xDVF_vox dx; yDVF_cm = xDVF_vox dy; zDVF_cm = xDVF_vox * dz;

-Aditya

On Sat, Jan 8, 2022 at 9:17 AM MohHu @.***> wrote:

Dear Sir,

Happy new year,

Is there any suggestion about the last post, which corresponds to how CERR specify DVF?

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-1008003528, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB4OQ4V4CPEUNBWH4NLUVBBO7ANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

MohHu commented 2 years ago

Dear Dr. adityaapte,

Hope you are well

I have two questions I would like to ask about:

Yours sincerely

MohHu commented 2 years ago

Dear Sir,

Good afternoon,

Is there any suggestions regarding previous post?

Yours sincerely

adityaapte commented 2 years ago

Hi, I am not quite sure what you mean by color blending. The deformable registration uses b-splines registration which can use MSE or MI metric. There are functions to deform scan, structure and dose based on the b-splines coefficients - warp_scan.m, warp_structures.m and warp_dose.m respectively. Can you perhaps post some images to give us more information?

On Mon, Jan 17, 2022 at 4:29 PM MohHu @.***> wrote:

Dear Sir,

Good afternoon,

Is there any suggestions regarding previous post?

Yours sincerely

— Reply to this email directly, view it on GitHub https://github.com/cerr/CERR/issues/661#issuecomment-1014898921, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNJB2OEURYV332BAZXI23UWSC4XANCNFSM5GQXAQ4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

MohHu commented 2 years ago

Dear Dr. Aditya,

Wit regard to your last post, I managed to run ''warp_scan function'', and the output has just been sent to you.

Yours sincerely

MohHu commented 2 years ago

Dear developer(s),

Good morning, I have been using deformable image registration applied in CERR, and It works and deforms scan from moving image image to base image. What I am working on is that I am trying to applied a CERR tool for DIR between the base and the moving CT of the patient to generate the displacement vector field (DVF) inside of the OARs on base image. However, when I use the DIR code on this link (''https://github.com/cerr/CERR/wiki/Deformable-Image-Registration-(DIR)''), the scan is deformed, but the structures are not.

I was wondering how I can deform the structure, and how I can extract the DVF for each OARs contour?

Thank you in advance for effort and I appreciate your help and your suggestion!

Yours sincerely