import os import threading def padding(segFilename, outputpath, pad_level,type): if not os.path.exists(segFilename): raise ValueError("Path %s does not exist." % segFilename) if type=='segementation': layers = importlayer(filename=segFilename, importer='[Teem Importer]', mode='label_mask') elif type=='scan': layers = importlayer(filename=segFilename, importer='[Teem Importer]', mode='data') else: raise ValueError("input type %s not recognised." % type) # get dimensions from group. this only works if the layers are in the first group loaded # TODO: find a way to access groupid from layerid. dims= get(stateid='group_0::dimensions') data_loc=get(stateid=layers[0]+'::centering') new_dims=[dims[0]+2*pad_level[0], dims[1]+2*pad_level[1],dims[2]+2*pad_level[2]] r_mn=[-pad_level[0],-pad_level[1],-pad_level[2]] if data_loc=='node': r_mx=[dims[0]+pad_level[0]-1,dims[1]+pad_level[1]-1,dims[2]+pad_level[2]-1] else: r_mx=[dims[0]+pad_level[0],dims[1]+pad_level[1],dims[2]+pad_level[2]] padded=resample(layerids=layers,x=new_dims[0],y=new_dims[1],z=new_dims[2],crop='true',range_min=r_mn,range_max=r_mx,padding='0',kernal='box') # this list is used to combine all the layers into a single data layer for exporting. # this implementation is dependant on the order of the layers, # which is a problem because seg3D currently preserve the order of layers when loaded. if type=='segmentation': if len(padded)>26: raise ValueError("Too many layers to use in this operation." % len(padded)) alpha=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] express='[RESULT = (A==1)*1' for k in range(1,len(padded)): tmp_exp=' + (' + alpha[k] + '==1)*' + str(k+1) express=express+tmp_exp express=express + ';]' wait_for_layer(padded[len(padded)-1]) grayscale=arithmeticfilter(layerids=padded,expressions=express,output_type='data',preserve_data_format='true') elif type=='scan': grayscale=padded[0]; wait_for_layer(grayscale) result=exportlayer(layer=grayscale,file_path=outputpath,exporter='[NRRD Exporter]',extension='.nrrd') print('file saved to '+outputpath) def wait_for_layer(layer): #checks to make sure that the layer is available before trying operations on it. MAX_ITERATIONS=1000 TIMEOUT=2 c = threading.Condition() c.acquire() layerStatus = get(stateid=layer+"::data") counter = 1 with c: while not layerStatus == "available": if counter > MAX_ITERATIONS: break counter += 1 c.wait(TIMEOUT) layerStatus = get(stateid=layer+"::data") print('wainting for '+layer)
Hi Jess,Somebody else created the project, and I'm not even sure how they got bits to be outside the image volume. Going back to the original project it looks like "mask layer -> transform". The "X" slice view does not go down further than the original volume either. Exporting to .nrrd and reading that in matlab has the same result as exporting to matlab.
I think the exporter is confused about the two layers not being aligned, but I'd sort of expect the export function to export what I see on the screen regardless.
Anyway, starting over I don't see any options for extending or resizing a grid, where can I find this?Thanks,SanderOn Fri, Feb 5, 2016 at 7:18 PM, Jess Tate <jess@sci.utah.edu> wrote:Hi Sander,There may be a couple of things going on here. The simplest thing to check is to make sure that you are exporting and importing the right layers. to create the segmentation 'out of bounds' you needed to expand the grid, which it seems that you did. Then you need to copy the entire layer to the new grid and save out the segementations from those new layers. You can try right clicking on the desired layer to export it also.The matlab format from Seg3D doesn't save the spacial information, if I remember correctly. That means if you have two volumes of different numbers of elements, one may be shifted depending on where the origin is supposed to be (as matlab will just set it to 0,0,0). It could also be the wrong size depending on what the relative spacing is supposed to be.cheers,JessOn Feb 5, 2016, at 4:09 AM, Sander Land <sander.land@gmail.com> wrote:Image 3: viewing in matlab, with hole clearly visible on the left.Image 2: Exporting, see the cap is component 7.Image 1: `cap' visible outside image range.Here are some screenshots:Hi Jess,I am using File->Export Segmentation. Both 'to matlab' and 'to nrrd' have the same problem.
http://imgur.com/a/Y5knbAs there does seem to be a component 7 in the matlab data, I've tried to see where it ends up, and turns out the problem is even worse than simple omission.
Component 7 gets translated to somewhere else in the volume and intersects with it, as shown here: http://imgur.com/a/tyCwd(output of figure(1); clf; isosurface(scirunnrrd.data == 1,0.5); hold on; p=patch(isosurface(scirunnrrd.data ="=7,0.5));set(p,'FaceColor','r');" axis equal)Thanks,SanderOn Thu, Feb 4, 2016 at 4:57 PM, Jess Tate <jess@sci.utah.edu> wrote:Hi Sander,
It’s a little tricky to understand what is going on, because when you export a segmentation, it should just save out the entire label mask. Is it possible you are exporting the original image on accident? You can try the 'Export Segmentation' option in the file menu, which has more controls than right clicking on the layer and exporting it that way. If that isn’t working, a screen shot may help determine what is going on.
cheers,
Jess
> On Feb 4, 2016, at 5:05 AM, sander.land@gmail.com wrote:
>
> I have an image data set which is missing a small part due to the bounds of
> the imaging. I've filled this in using the paint tool to make a smooth shape.
> However, when exporting the data set it's cut off again at the original
> bounds. Is there a way to extend these bounds and export the entire
> segmentation?
>
> Thanks,
> Sander
Archive powered by MHonArc 2.6.18.