Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dicom index order is reversed #1403

Closed
LeoReubelt opened this issue Jun 14, 2023 · 18 comments
Closed

Dicom index order is reversed #1403

LeoReubelt opened this issue Jun 14, 2023 · 18 comments
Labels
question Further information is requested
Milestone

Comments

@LeoReubelt
Copy link

LeoReubelt commented Jun 14, 2023

I had been using dwv version 0.30.8.
And setting the index as shown below.

const vc = dwvAppRef.current
  ?.getActiveLayerGroup()
  ?.getActiveViewLayer()
  .getViewController();
if (!!!vc) {
  return;
}

const index = vc.getCurrentIndex();
const values = index.getValues();
values[2] = sliceNumber;
vc.setCurrentIndex(new dwv.math.Index(values));

Then I upgraded to version 0.31.2, followed by 0.32.0. With both of them, the indices are reversed. When i set the first index, it shows the image for the last index. And when I set the last index, it shows the image for the first. Is there a reason for this? How can I correct it?

@LeoReubelt
Copy link
Author

Also, App.getState() is returning different values for position. It was image position patient. And now it looks like number of images - currentIndex.

@ivmartel ivmartel added the question Further information is requested label Jun 15, 2023
@ivmartel ivmartel added this to the 0.33.0 milestone Jun 15, 2023
@ivmartel
Copy link
Owner

v0.31fixed some issues the code was having with non axial data: it uses the proper values of the orientation matrix and sets the origin to the first element of the image position patient array. I though these would compensate each other. Does your image have a specific orientation? Would it be complicated for you to switch indices?

You're correct about the state, the position is now the index when it used to be the position. Sorry for that, it should of triggered a version change... Now I am not sure about the future of this state file, I would prefer using something more dicom compatible and am searching for solutions (see #1020).

@LeoReubelt
Copy link
Author

@ivmartel - thanks for the response. I don't know if there is a specific orientation. Can you tell me how to check? Changing the index is very easy. And that is what I have currently done. My only concern is, will it always be the same? Or will if be different for different dicom series. And if it will be different, what is the logic to determine that?

@ivmartel
Copy link
Owner

The orientation is given by the 'Image Orientation (Patient)' dicom attribute (00200037, doc). It specifies two direction vectors that are:

  • 1, 0, 0 and 0, 1, 0 for axial data
  • 0, 1, 0 and 0, 0, 1 for sagittal data
  • 1, 0, 0 and 0, 0, 1 for coronal data
    (the values could not be zeros and ones, the major axes are given by the largest values that can also be negative)

The current code sets the slice with the lowest Image Position Patient (00200032, doc) as the slice with index 0 for axial data.

@LeoReubelt
Copy link
Author

orientation is 1,0,0,0,1,0. i understand how it is being set. that helps. thanks.

@LeoReubelt
Copy link
Author

i understand, we can close this. thank you.

@LeoReubelt
Copy link
Author

LeoReubelt commented Jun 20, 2023

@ivmartel
Since the slices are sorted by image patient position, i need to be able to get the instance number for a given slice. And i am doing that with the following...

const layerGroup = dwvApp.getActiveLayerGroup();
const viewLayer = layerGroup.getActiveViewLayer();
const viewController = viewLayer.getViewController();
const meta = dwvApp.getMetaData(viewLayer.getDataIndex());
const currentIndex = viewController.getCurrentIndex().getValues();
const instanceNumberValue = meta[`00200013`];

When I open my test file in osirix, and sort by instance number, i get the reversed order that i get with dwv.
That makes sense to me based on the discussion above.
But based on that, I would expect that the instance numbers would be in reverse order to the image patient position.
But there seems to be no ordering to instance number.

So how do i get the corresponding instance number?

@LeoReubelt
Copy link
Author

the following is meta[00200032].value

{
    "1": [
        "-249.51171875",
        "-491.51171875",
        "105"
    ],
    "2": [
        "-249.51171875",
        "-491.51171875",
        "103.5"
    ],
    "3": [
        "-249.51171875",
        "-491.51171875",
        "102"
    ],
    "4": [
        "-249.51171875",
        "-491.51171875",
        "100.5"
    ],
    "5": [
        "-249.51171875",
        "-491.51171875",
        "99"
    ],
    "6": [
        "-249.51171875",
        "-491.51171875",
        "97.5"
    ],
    "7": [
        "-249.51171875",
        "-491.51171875",
        "96"
    ],
    "8": [
        "-249.51171875",
        "-491.51171875",
        "94.5"
    ],
    "9": [
        "-249.51171875",
        "-491.51171875",
        "93"
    ],
    "10": [
        "-249.51171875",
        "-491.51171875",
        "91.5"
    ],
    "11": [
        "-249.51171875",
        "-491.51171875",
        "90"
    ],
    "12": [
        "-249.51171875",
        "-491.51171875",
        "88.5"
    ],
    "13": [
        "-249.51171875",
        "-491.51171875",
        "87"
    ],
    "14": [
        "-249.51171875",
        "-491.51171875",
        "85.5"
    ],
    "15": [
        "-249.51171875",
        "-491.51171875",
        "84"
    ],
    "16": [
        "-249.51171875",
        "-491.51171875",
        "82.5"
    ],
    "17": [
        "-249.51171875",
        "-491.51171875",
        "81"
    ],
    "18": [
        "-249.51171875",
        "-491.51171875",
        "79.5"
    ],
    "19": [
        "-249.51171875",
        "-491.51171875",
        "78"
    ],
    "20": [
        "-249.51171875",
        "-491.51171875",
        "76.5"
    ],
    "21": [
        "-249.51171875",
        "-491.51171875",
        "75"
    ],
    "22": [
        "-249.51171875",
        "-491.51171875",
        "73.5"
    ],
    "23": [
        "-249.51171875",
        "-491.51171875",
        "72"
    ],
    "24": [
        "-249.51171875",
        "-491.51171875",
        "70.5"
    ],
    "25": [
        "-249.51171875",
        "-491.51171875",
        "69"
    ],
    "26": [
        "-249.51171875",
        "-491.51171875",
        "67.5"
    ],
    "27": [
        "-249.51171875",
        "-491.51171875",
        "66"
    ],
    "28": [
        "-249.51171875",
        "-491.51171875",
        "64.5"
    ],
    "29": [
        "-249.51171875",
        "-491.51171875",
        "63"
    ],
    "30": [
        "-249.51171875",
        "-491.51171875",
        "61.5"
    ],
    "31": [
        "-249.51171875",
        "-491.51171875",
        "60"
    ],
    "32": [
        "-249.51171875",
        "-491.51171875",
        "58.5"
    ],
    "33": [
        "-249.51171875",
        "-491.51171875",
        "57"
    ],
    "34": [
        "-249.51171875",
        "-491.51171875",
        "55.5"
    ],
    "35": [
        "-249.51171875",
        "-491.51171875",
        "54"
    ],
    "36": [
        "-249.51171875",
        "-491.51171875",
        "52.5"
    ],
    "37": [
        "-249.51171875",
        "-491.51171875",
        "51"
    ],
    "38": [
        "-249.51171875",
        "-491.51171875",
        "49.5"
    ],
    "39": [
        "-249.51171875",
        "-491.51171875",
        "48"
    ],
    "40": [
        "-249.51171875",
        "-491.51171875",
        "46.5"
    ],
    "41": [
        "-249.51171875",
        "-491.51171875",
        "45"
    ],
    "42": [
        "-249.51171875",
        "-491.51171875",
        "43.5"
    ],
    "43": [
        "-249.51171875",
        "-491.51171875",
        "42"
    ],
    "44": [
        "-249.51171875",
        "-491.51171875",
        "40.5"
    ],
    "45": [
        "-249.51171875",
        "-491.51171875",
        "39"
    ],
    "46": [
        "-249.51171875",
        "-491.51171875",
        "37.5"
    ],
    "47": [
        "-249.51171875",
        "-491.51171875",
        "36"
    ],
    "48": [
        "-249.51171875",
        "-491.51171875",
        "34.5"
    ],
    "49": [
        "-249.51171875",
        "-491.51171875",
        "33"
    ],
    "50": [
        "-249.51171875",
        "-491.51171875",
        "31.5"
    ],
    "51": [
        "-249.51171875",
        "-491.51171875",
        "30"
    ],
    "52": [
        "-249.51171875",
        "-491.51171875",
        "28.5"
    ],
    "53": [
        "-249.51171875",
        "-491.51171875",
        "27"
    ],
    "54": [
        "-249.51171875",
        "-491.51171875",
        "25.5"
    ],
    "55": [
        "-249.51171875",
        "-491.51171875",
        "24"
    ],
    "56": [
        "-249.51171875",
        "-491.51171875",
        "22.5"
    ],
    "57": [
        "-249.51171875",
        "-491.51171875",
        "21"
    ],
    "58": [
        "-249.51171875",
        "-491.51171875",
        "19.5"
    ],
    "59": [
        "-249.51171875",
        "-491.51171875",
        "18"
    ],
    "60": [
        "-249.51171875",
        "-491.51171875",
        "16.5"
    ],
    "61": [
        "-249.51171875",
        "-491.51171875",
        "15"
    ],
    "62": [
        "-249.51171875",
        "-491.51171875",
        "13.5"
    ],
    "63": [
        "-249.51171875",
        "-491.51171875",
        "12"
    ],
    "64": [
        "-249.51171875",
        "-491.51171875",
        "10.5"
    ],
    "65": [
        "-249.51171875",
        "-491.51171875",
        "9"
    ],
    "66": [
        "-249.51171875",
        "-491.51171875",
        "7.5"
    ],
    "67": [
        "-249.51171875",
        "-491.51171875",
        "6"
    ],
    "68": [
        "-249.51171875",
        "-491.51171875",
        "4.5"
    ],
    "69": [
        "-249.51171875",
        "-491.51171875",
        "3"
    ],
    "70": [
        "-249.51171875",
        "-491.51171875",
        "1.5"
    ],
    "71": [
        "-249.51171875",
        "-491.51171875",
        "0"
    ],
    "72": [
        "-249.51171875",
        "-491.51171875",
        "-1.5"
    ],
    "73": [
        "-249.51171875",
        "-491.51171875",
        "-3"
    ],
    "74": [
        "-249.51171875",
        "-491.51171875",
        "-4.5"
    ],
    "75": [
        "-249.51171875",
        "-491.51171875",
        "-6"
    ],
    "76": [
        "-249.51171875",
        "-491.51171875",
        "-7.5"
    ],
    "77": [
        "-249.51171875",
        "-491.51171875",
        "-9"
    ],
    "78": [
        "-249.51171875",
        "-491.51171875",
        "-10.5"
    ],
    "79": [
        "-249.51171875",
        "-491.51171875",
        "-12"
    ],
    "80": [
        "-249.51171875",
        "-491.51171875",
        "-13.5"
    ],
    "81": [
        "-249.51171875",
        "-491.51171875",
        "-15"
    ],
    "82": [
        "-249.51171875",
        "-491.51171875",
        "-16.5"
    ],
    "83": [
        "-249.51171875",
        "-491.51171875",
        "-18"
    ],
    "84": [
        "-249.51171875",
        "-491.51171875",
        "-19.5"
    ],
    "85": [
        "-249.51171875",
        "-491.51171875",
        "-21"
    ],
    "86": [
        "-249.51171875",
        "-491.51171875",
        "-22.5"
    ],
    "87": [
        "-249.51171875",
        "-491.51171875",
        "-24"
    ],
    "88": [
        "-249.51171875",
        "-491.51171875",
        "-25.5"
    ],
    "89": [
        "-249.51171875",
        "-491.51171875",
        "-27"
    ],
    "90": [
        "-249.51171875",
        "-491.51171875",
        "-28.5"
    ],
    "91": [
        "-249.51171875",
        "-491.51171875",
        "-30"
    ],
    "92": [
        "-249.51171875",
        "-491.51171875",
        "-31.5"
    ],
    "93": [
        "-249.51171875",
        "-491.51171875",
        "-33"
    ],
    "94": [
        "-249.51171875",
        "-491.51171875",
        "-34.5"
    ],
    "95": [
        "-249.51171875",
        "-491.51171875",
        "-36"
    ],
    "96": [
        "-249.51171875",
        "-491.51171875",
        "-37.5"
    ],
    "97": [
        "-249.51171875",
        "-491.51171875",
        "-39"
    ],
    "98": [
        "-249.51171875",
        "-491.51171875",
        "-40.5"
    ],
    "99": [
        "-249.51171875",
        "-491.51171875",
        "-42"
    ],
    "100": [
        "-249.51171875",
        "-491.51171875",
        "-43.5"
    ],
    "101": [
        "-249.51171875",
        "-491.51171875",
        "-45"
    ],
    "102": [
        "-249.51171875",
        "-491.51171875",
        "-46.5"
    ],
    "103": [
        "-249.51171875",
        "-491.51171875",
        "-48"
    ],
    "104": [
        "-249.51171875",
        "-491.51171875",
        "-49.5"
    ],
    "105": [
        "-249.51171875",
        "-491.51171875",
        "-51"
    ],
    "106": [
        "-249.51171875",
        "-491.51171875",
        "-52.5"
    ],
    "107": [
        "-249.51171875",
        "-491.51171875",
        "-54"
    ],
    "108": [
        "-249.51171875",
        "-491.51171875",
        "-55.5"
    ],
    "109": [
        "-249.51171875",
        "-491.51171875",
        "-57"
    ],
    "110": [
        "-249.51171875",
        "-491.51171875",
        "-58.5"
    ],
    "111": [
        "-249.51171875",
        "-491.51171875",
        "-60"
    ],
    "112": [
        "-249.51171875",
        "-491.51171875",
        "-61.5"
    ],
    "113": [
        "-249.51171875",
        "-491.51171875",
        "-63"
    ],
    "114": [
        "-249.51171875",
        "-491.51171875",
        "-64.5"
    ],
    "115": [
        "-249.51171875",
        "-491.51171875",
        "-66"
    ],
    "116": [
        "-249.51171875",
        "-491.51171875",
        "-67.5"
    ],
    "117": [
        "-249.51171875",
        "-491.51171875",
        "-69"
    ],
    "118": [
        "-249.51171875",
        "-491.51171875",
        "-70.5"
    ],
    "119": [
        "-249.51171875",
        "-491.51171875",
        "-72"
    ],
    "120": [
        "-249.51171875",
        "-491.51171875",
        "-73.5"
    ],
    "121": [
        "-249.51171875",
        "-491.51171875",
        "-75"
    ],
    "122": [
        "-249.51171875",
        "-491.51171875",
        "-76.5"
    ],
    "123": [
        "-249.51171875",
        "-491.51171875",
        "-78"
    ],
    "124": [
        "-249.51171875",
        "-491.51171875",
        "-79.5"
    ],
    "125": [
        "-249.51171875",
        "-491.51171875",
        "-81"
    ],
    "126": [
        "-249.51171875",
        "-491.51171875",
        "-82.5"
    ],
    "127": [
        "-249.51171875",
        "-491.51171875",
        "-84"
    ],
    "128": [
        "-249.51171875",
        "-491.51171875",
        "-85.5"
    ],
    "129": [
        "-249.51171875",
        "-491.51171875",
        "-87"
    ],
    "130": [
        "-249.51171875",
        "-491.51171875",
        "-88.5"
    ],
    "131": [
        "-249.51171875",
        "-491.51171875",
        "-90"
    ],
    "132": [
        "-249.51171875",
        "-491.51171875",
        "-91.5"
    ],
    "133": [
        "-249.51171875",
        "-491.51171875",
        "-93"
    ],
    "134": [
        "-249.51171875",
        "-491.51171875",
        "-94.5"
    ],
    "135": [
        "-249.51171875",
        "-491.51171875",
        "-96"
    ],
    "136": [
        "-249.51171875",
        "-491.51171875",
        "-97.5"
    ],
    "137": [
        "-249.51171875",
        "-491.51171875",
        "-99"
    ],
    "138": [
        "-249.51171875",
        "-491.51171875",
        "-100.5"
    ],
    "139": [
        "-249.51171875",
        "-491.51171875",
        "-102"
    ],
    "140": [
        "-249.51171875",
        "-491.51171875",
        "-103.5"
    ],
    "141": [
        "-249.51171875",
        "-491.51171875",
        "-105"
    ]
}

@LeoReubelt
Copy link
Author

and below is meta[00200013].value

[ "13", "27", "65", "68", "9", "22", "114", "109", "12", "83", "78", "67", "138", "14", "120", "87", "124", "63", "23", "135", "113", "44", "98", "59", "126", "85", "26", "137", "107", "131", "118", "129", "92", "4", "53", "74", "81", "28", "35", "102", "1", "32", "43", "76", "133", "141", "3", "34", "60", "55", "72", "94", "2", "101", "89", "33", "106", "42", "50", "116", "91", "61", "49", "29", "96", "57", "140", "70", "110", "104", "108", "39", "17", "125", "79", "16", "66", "41", "82", "10", "15", "8", "24", "64", "20", "25", "84", "21", "112", "99", "58", "46", "136", "123", "62", "45", "121", "86", "7", "38", "69", "18", "36", "11", "77", "117", "139", "48", "134", "130", "71", "93", "115", "75", "52", "80", "30", "128", "105", "97", "40", "31", "56", "6", "119", "111", "47", "88", "73", "54", "103", "95", "100", "51", "37", "132", "122", "90", "5", "19", "127" ]

@LeoReubelt LeoReubelt reopened this Jun 20, 2023
@LeoReubelt
Copy link
Author

@ivmartel - i reopened this issue because i can't seem to figure out how to correlate instance number with image patient position. if you could please see above.

@ivmartel
Copy link
Owner

You are right, the instance numbers are not sorted and they is no correspondence between the image position patients and the instance numbers. Why are you looking for this correspondence?

@LeoReubelt
Copy link
Author

@ivmartel - thanks for the response. i think there should be. in osirix, when i sort by instance number, i get the reverse order form dwv. when i sort by image patient position i get the same order. that would suggest to me, that they are related.

@ivmartel
Copy link
Owner

ivmartel commented Jun 23, 2023

Sorry, I answered too quickly, the viewer uses the instance number as an index for the meta data when tags are different between instances, so there is a correspondence. But it does not sort the instance number list.

Do you need this sort for a specific purpose?

@LeoReubelt
Copy link
Author

maybe. is there a way for me to get the instance number for the currently set index? we are using a different parser for meta data. and i need to be able to align those results with the results from dwv. and the way i would generally do that is by instance number.

@ivmartel
Copy link
Owner

Not that I can think of...

As a side note, the instance number is not a compulsory DICOM tag. The tag that can be used to uniquely identify a slice is its SOP Instance UID. I use the instance number because the UID can be a long string... And it seems to have worked until now...

@LeoReubelt
Copy link
Author

Thanks @ivmartel . That helps.

@gams123
Copy link

gams123 commented Jun 24, 2023

The code you provided is using the dwv library to get the current index of a DICOM slice and update it with a new value. The code seems to be correct and should work as expected.

However, since dwv is an external library, it's possible that the version you are using has different syntax or implementation details compared to the version I'm familiar with. Therefore, it's possible that the code you provided may not work as expected with version 0.30.8 of dwv.

If you encounter any issues with the code, you can try checking the documentation or release notes of the dwv library to see if there were any changes to the syntax or API in the version you are using. You can also try updating to a newer version of the library to see if that resolves any issues you may be experiencing.

@gams123
Copy link

gams123 commented Jun 24, 2023

To fix this issue, you can use the following approach to get the current index and update it with a new value:

const vc = dwvAppRef.current?.getViewController();
if (!vc) {
  return;
}

const currentIndex = vc.getCurrentPosition().k;
const newIndex = [currentIndex[0], currentIndex[1], sliceNumber];
vc.setCurrentPosition(newIndex);

Here, getCurrentPosition() method is used instead of getCurrentIndex() to get the current index and setCurrentPosition() method is used instead of setCurrentIndex() to update the index with a new value.

Using this approach, the code should work successfully with all versions of dwv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants