i plan to make a function which was a variable to record made label of segment by uesr.the best state was that relationship was one to one between label and segment.can we do it? please tell me which material i need look if the answer was yes.
Thanks
I don’t understand exactly what you want to do, but loading a labelmap volume as segmentation is very easy to do. You can find examples for this and many other segmentation related tasks in the script repository.
no,no,i am sorry for not speak clearly, I mean, I want to create a new text label, not a label map type in 3Dslicer, because in fact, a label map can have multiple segments, right? But for each segment, I want to add an attribute to them and finally export these attributes as Json. Thank
You can set “tags” (list of tag/value pairs) for each segment in a segmentation. This is written to the .seg.nrrd file but of course you can also write it out into another file in any format.
Hi,Lasso.I have seen document of 3DSlicer,But I seem had didn’t see usage of tags of segment.
I plan the next step was that Can put Radio value into currently selection Segment_1 in below picture when I press the get Value Button.(What I do now just print ) Could you give me a code demo?
and finally do we have some exist abled API for export function? : ) : -)
You can call mySegmentationNode.GetSegme tation().GetSegment("aSegmentID").SetTag("someTag", "some value")
. These tagged values are saved into the segmentation nrrd file.
Lasso,Thank you help! MySegmentationNode GetSegmetation(). This is missing n. It should be Getsegmentation(). haha. Anyway, I successfully combined the method you provided to give each segment_ 1/_ 2/_ 3 has set the corresponding Tag. However, after saving it as nrrd through export to file, I did not see the Tag when reading through ITK or Pydicom.
So I changed my mindset to complete the task and obtain each segment_ 1/_ Bounds of 2 and corresponding mask information. But I call activeSegment When GetBounds(), the console displays TypeError: GetBounds() takes exactly 1 argument (0 given), but I have looked at the function description but am still not quite sure what parameters to give (purpose: I want to obtain the boundaries of the real world coordinate system, that is, the Max and Min of the coordinate information xyz that is consistent with the dicom metadata, and what parameters should I pass to GetBounds to obtain these 6 information). Can you please explain how to obtain mask data from x/y/zMax Min after solving this problem?
—update—
I tried to obtain the properties inside through the GetRepresentation method of the vtkSegment class. That is, under Representations in the above figure. However, I call segment GetRepresentation ('extent ')
Segment GetRepresentation ('spating ') returns None. When I pass in the self parameter, the display error must be a string. This feels like I can see but cannot touch it.
my version was 5.0.3.
Please tell me how to get these.
pydicom is not related. ITK may discard metadata that it does not know about (have a look at the metadata dictionary, though, you may find it there). You can surely use pynrrd to read all metadata, including segment tags.
Make sure you use the “Save” function to store all segmentation metadata. “Export to files” feature removes all custom metadata.
That’s the correct behavior, because there is no such representation. You can find working examples of getting representations in the script repository.
Thank you, lasso. I tried the way you said. It was to read the Segmentation node saved through the save method through pynrrd, and it does contain the tags I added. But it seems that each tag cannot correspond to its own Extent area, because the attribute Extent area accumulates information about all Segments. Whether it’s a segment_ 1 or Segment_ 2. Their Extents are the same.
Part2: I also obtained Bounds for each Segment. I found that it is also consistent with the previous Extent situation, so I tested it several times and found that it seems to be a Segment_1/_2/_3 under a Segmentation actually share a Representation (OrientImageData), right? I tried clicking on the button, segment. RemoveRepresentation (“Binary labelmap”), and then SetMasterRepresentationToBinaryLabelmap() to add a new Rep, but it didn’t take effect and I couldn’t even draw with a brush 0__0
Overall, I would like to record segmentation_1. Segmentation_2 independent Bounds information.Like the following picture
Extent
refers to the start/end extent of the image. In a VTK image, start extent can be anything (0, positive, or negative), while in a NRRD image it is always (0,0,0). Extent is stored in the segment metadata so that we can save and load any vtkImageData object without losing the original extent.
If you need the effective extent of a segment (extent of the bounding of non-zero voxels of the segment) then you need to store it in the segment tags yourself.