GithubHelp home page GithubHelp logo

Comments (4)

lagru avatar lagru commented on May 27, 2024

Thanks for the report!

If I manually rename both the file and its directory, i.e. to "CellLine1_1Hz_Field_2.NDTiffStack.tif", the command io.imread(CellLine1_1Hz_Field_2.NDTiffStack.tif) provides the following error:

[Errno 2] No such file or directory: CellLine1_1Hz_Field_2/CellLine1_1Hz_Field_1.NDTiffStack.tif

This seems a little confusing to me. I'm not sure if this is an oversight while writing the report or if this points to the actual cause of the issue. But these paths don't line up. You rename to "CellLine1_1Hz_Field_2.NDTiffStack.tif" including the directory but the error message indicates that you used "CellLine1_1Hz_Field_1.NDTiffStack.tif". Can you check if that's the case and maybe try to describe the issue in clearer more explicit terms? E.g.

# path before renaming
directory_1/file_name_1.tif
# path after renaming
directory_2/file_name_2.tif

It would be even better if you could provide a snippet to reproduce this. 🙏

Note that we are planning on deprecating the IO plugin infrastructure altogether (#7353). You could also try to use imageio directly.

from scikit-image.

l-sala avatar l-sala commented on May 27, 2024

Thank you, Lars, for the quick reply. Apologies for the confusion.

That point is the actual cause of the issue. I follow up below with some specifications.

# 1. path before renaming
## correctly read by io.imread()
file_name_1_directory/file_name_1.NDTiffStack.tif

# 2. path after renaming
## not read by io.imread() 
file_name_2_directory/file_name_2.NDTiffStack.tif

### Here the error that is outputed will be:
[Errno 2] No such file or directory: 'file_name_2_directory/file_name_1.NDTiffStack.tif' (yes, it's looking for the original file name into the renamed directory)

# 3. solution that works
## if I duplicate the file at point no. 2 and I rename one of the two as the file in point no. 1, both are correctly read.
file_name_2_directory/file_name_1.NDTiffStack.tif
file_name_2_directory/file_name_2.NDTiffStack.tif

To me, it seems that io.imread() somehow have access to the pre-renamed filename in the renamed folder, and this of course causes the error as the file in the new folder has indeed another name, since it has been indeed renamed. I have no clue on how/where io.imread() gets the information on the old file name. I already emptied Win10 cache.

The snippet is very minimal in my case, as the error is recreated already with:

from skimage import io
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

main_dir = input("Enter the path to the main directory: ") #this would be, e.g., file_name_1_directory or file_name_2_directory

tif_files = []
for root, dirs, files in os.walk(main_dir):
    for file in files:
        if file.endswith('.tif'):
            tif_path = os.path.join(root, file)
            tif_files.append(tif_path)

for tif_path in tqdm(tif_files, desc="Processing .tif files"):
    try:
        # Check if the path has enough directories
        tif_path_parts = tif_path.split(os.sep)
        # Extract the second and third from the last directory names
        if len(tif_path_parts) >= 4:
            dir2 = tif_path_parts[-3]  # Second from the last
            last = tif_path_parts[-1]  # This is the file
            # Combine them as a new file name
            file_name = f"{dir2}_{last}"

            stack = io.imread(tif_path)

The files to be analyzed are 2-3 Gb in size. Let me know if you think one sample is required.

from scikit-image.

cgohlke avatar cgohlke commented on May 27, 2024

The metadata for NDTiff stacks, including the file names where image data are stored, are found in a separate NDTiff.index file. Renaming a NDTiff file invalidates the metadata. Try to remove the NDTiff.index file or tell tifffile not to use NDTiff metadata: imread(..., is_ndtiff=False).

from scikit-image.

l-sala avatar l-sala commented on May 27, 2024

The metadata for NDTiff stacks, including the file names where image data are stored, are found in a separate NDTiff.index file. Renaming a NDTiff file invalidates the metadata. Try to remove the NDTiff.index file or tell tifffile not to use NDTiff metadata: imread(..., is_ndtiff=False).

Thanks a lot; the imread(..., is_ndtiff=False) solved the issue completely.

from scikit-image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.