Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Band Tif #14

Open
mthsdiniz-usp opened this issue Feb 22, 2024 · 2 comments
Open

Multiple Band Tif #14

mthsdiniz-usp opened this issue Feb 22, 2024 · 2 comments

Comments

@mthsdiniz-usp
Copy link

mthsdiniz-usp commented Feb 22, 2024

Hey @jaspersiebring , first of all, congrats on making this library!

I'm trying to convert a set o 18 band TIF files and theirs respective geojson labels but i'm facing some problems when trying to do that.

Each one of my images has 18 bands but their height and width vary a little. When trying to feed the 18 band tif, i end up with the following error:

image

When trying to feed a 3 band file, i end up with the following error:

image

This is the code i'm using:

# Replace this with your preferred output paths
data_path = pathlib.Path("../raster-ml/original_size/coco/images")
json_path = pathlib.Path("../raster-ml/original_size/coco/json")

# Dimensions of the moving window and output images
width, height = 256, 256

# Starting a new CocoDataset
description = "My First Dataset"
contributor = "User"

# version and date_created are automatically set
dataset = create_dataset(description=description, contributor=contributor)
# You can also load existing COCO datasets
# dataset = load_dataset(json_path=json_path)

# Loading GIS data with rasterio and geopandas
labels = gpd.read_file('../raster-ml/original_size/labels_bbox/S39W061-180_20-01-19.geojson')
raster_source = rasterio.open('test.tif')

# (Optional) Apply any spatial or attribute queries here
# labels = labels.loc[labels["ids"].isin([1, 2, 3])]
# labels = labels.loc[labels.within(some_polygon)]

# Find and save all Annotation instances
dataset = append_dataset(
    dataset=dataset,
    images_dir=data_path,
    src=raster_source,
    labels=labels,
    window_bounds=[(width, height)],
    id_attribute=None,  # column with category_id values
    name_attribute="ids",  # column with category_name values
    super_attribute=None,  # optional column with super_category values
)

# Encode CocoDataset instance as JSON and save to json_path
save_dataset(dataset=dataset, json_path=json_path)

Also, is there a way to feed in a pre-chipped dataset (256x256) in order to create the COCO Dataset?

I already have all tif files and corresponding geojson pre-chipped....

@jaspersiebring
Copy link
Owner

Thanks so much! The variable dimensions should not be a problem but I do wonder about the driver that is being assigned.

If you don't specify a driver manually, Rasterio will just assign one based on the file's extension which appears to be JPEG. This driver is then also used throughout other operations like the clipping which assumes a georeferenced file/appropriate driver (which I suspect is not the case right now). Can you verify the file extension?

JPEG is supported by GeoCOCO through GDAL but they're not all created equally (see drivers). You can try manually specifying a different driver when you run rasterio.open(driver=some_driver) with some_driver being anything from rasterio.drivers().

How were these images created? I can try it for myself if you are okay with sending me a sample (won't do anything else with it).

@mthsdiniz-usp
Copy link
Author

mthsdiniz-usp commented Feb 22, 2024

Hey Jasper, i'm feeding a tif file to rasterio in order to produce the COCO dataset, but even so it's trying to output a JPEG. If it can output a tif file without even creating patches that would be even better.

Here are a sample of the files i'm using:
image.zip

image.tif = 18 band imagery 256 x 256
label.geojson = rectangular polygon around my objects
label.tif = binary mask for each one of the objects

ps: i zipped the files because github does not accept the formats.

Thanks a lot for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants