google / neuroglancer

WebGL-based viewer for volumetric data
Apache License 2.0
1.02k stars 283 forks source link

There is no 3D model displayed after converting the nrrd format or tif images into the required data for neuroplanner #605

Open scorpio921 opened 1 week ago

scorpio921 commented 1 week ago

code

  import numpy as np
  from cloudvolume import CloudVolume
  from cloudvolume.lib import Bbox
  import nrrd

  print(dir(nrrd))

  nrrd_file_path = './I.nrrd'
  data, header = nrrd.read(nrrd_file_path)

  print("Original NRRD data shape:", data.shape)
  print("Original NRRD data type:", data.dtype)
  print("Data min:", np.min(data))
  print("Data max:", np.max(data))

  normalized_data = ((data - np.min(data)) / (np.max(data) - np.min(data)) * 255).astype(np.uint8)

  print("Normalized data min:", np.min(normalized_data))
  print("Normalized data max:", np.max(normalized_data))
  print("Normalized data type:", normalized_data.dtype)

  output_path = 'file:///path/to/nrrd'
  volume = CloudVolume(output_path, info={
      'type': 'image',
      'data_type': 'uint8', 
      'num_channels': 1,     
      'scales': [{
          'resolution': [2,2, 2],  
          'size': normalized_data.shape,  
          "key": "d2",  
          'chunk_sizes': [[64, 64, 64]],  
          'encoding': 'raw'  
      }]
  }, compress=False)

  volume.commit_info()

  bbox = Bbox((0, 0, 0), normalized_data.shape)

  volume[bbox] = normalized_data

  downloaded_data = volume[bbox]
  print("Downloaded data shape:", downloaded_data.shape)
  print("Downloaded data type:", downloaded_data.dtype)
  print("Downloaded data min:", np.min(downloaded_data))
  print("Downloaded data max:", np.max(downloaded_data))

  print("TIFF data has been converted and uploaded to precomputed format.")

image

jbms commented 1 week ago

By 3-d model, do you mean volume rendering in the 3d panel?

You have to enable that by selecting "Volume rendering" in the "Rendering" tab of the layer.

scorpio921 commented 1 week ago

@jbms Thanks ,you are right, but, I have one more question. Why doesn't my 2D image have rendering nodes and the 3D model looks very blurry? Do you know why image

image