Пример #1
0
def writeN5(img, path, dataset_name, blockSize, gzip_compression_level=4, n_threads=0):
  """ img: the RandomAccessibleInterval to store in N5 format.
      path: the directory to store the N5 data.
      dataset_name: the name of the img data.
      blockSize: an array or list as long as dimensions has the img, specifying
                 how to chop up the img into pieces.
      gzip_compression_level: defaults to 4, ranges from 0 (no compression) to 9 (maximum;
                              see java.util.zip.Deflater for details.).
      n_threads: defaults to as many as CPU cores, for parallel writing. """
  N5Utils.save(img, N5FSWriter(path, GsonBuilder()),
               dataset_name, blockSize,
               GzipCompression(gzip_compression_level) if gzip_compression_level > 0 else RawCompression(),
               newFixedThreadPool(n_threads=n_threads, name="jython-n5writer"))
Пример #2
0
def readN5(path, dataset_name, show=None):
    """ path: filepath to the folder with N5 data.
      dataset_name: name of the dataset to use (there could be more than one).
      show: defaults to None. "IJ" for virtual stack, "BDV" for BigDataViewer.
      
      If "IJ", returns the RandomAccessibleInterval and the ImagePlus.
      If "BDV", returns the RandomAccessibleInterval and the bdv instance. """
    img = N5Utils.open(N5FSReader(path, GsonBuilder()), dataset_name)
    if show:
        if "IJ" == show:
            return img, showStack(img, title=dataset_name)
        elif "BDV" == show:
            return img, showBDV(img, title=dataset_name)
    return img
        URL url = new URL (HOST + PATH + params);

        List<RequestBody> objList = new ArrayList<>();
        objList.add(new RequestBody(text));
        String content = new Gson().toJson(objList);
        translatedText = Post(url, content);
    }

    /*
     *  This function was not written by the team.
     *  Source: https://docs.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-java-translate
     */
    public String prettify(String json_text) {
        JsonParser parser = new JsonParser();
        JsonElement json = parser.parse(json_text);
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        return gson.toJson(json);
    }

    /*
     *  Returns this part of json_text:
     *      "text":"[EVERYTHING IN HERE]","to":
     */
    public String getTextFromJson (String json_text) {
        return json_text.substring(json_text.indexOf("\"text\":") + 8, json_text.indexOf("\",\"to\":"));
    }

    /*
     *  Set the params global variable to be used in the next text translation.
     *  Unfortunately, some of these languages can't be used as of right now, because
     *  they're characters can't be handled by the matching algorithm.
Пример #4
0
dataset_name = "4D series"
if not os.path.exists(n5path):
    # Create directory for storing the dataset in N5 format
    os.mkdir(n5path)
    # An array or list as long as dimensions has the img,
    # specifying how to chop up the img into pieces.
    blockSize = [128, 128, 128, 1]  # each block is about 2 MB
    # Compression: 0 means none. 4 is sensible. Can go up to 9.
    # See java.util.zip.Deflater for details
    gzip_compression_level = 4
    # Threads: as many as CPU cores, for parallel writing
    exe = Executors.newFixedThreadPool(
        Runtime.getRuntime().availableProcessors())

    N5Utils.save(
        cachedCellImg, N5FSWriter(n5path, GsonBuilder()), dataset_name,
        blockSize,
        GzipCompression(gzip_compression_level)
        if gzip_compression_level > 0 else RawCompression(), exe)

    # The above waits until all jobs have run. Then:
    exe.shutdown()

# Interestingly:
# KLB format: 11 stacks, 407 MB total
# N5 format with GZIP compression level 4: 688 files, 584 MB total.

# Open the N5 dataset
imgN5 = N5Utils.open(N5FSReader(n5path, GsonBuilder()), dataset_name)

# ... as a virtual stack