Giter Site home page Giter Site logo

image_slicer's Introduction

Image Slicer

This project is no longer maintained.

Downloads Build Status Documentation Code style: black Code Coverage

Splitting images into tiles. With Python. Since 2013.


Installation

Latest Stable Release: pip install image_slicer
Current Development Head: pip install git+https://github.com/samdobson/image_slicer.git

Quick Start

Slice your images either with the command line utility:

$ slice-image cake.png -n 4

... or from your Python script:

from image_slicer import slice

slice('cake.png', 4)

Documentation

For full package documentation please visit samdobson.github.io/image_slicer.

Development

See CONTRIBUTING.md for details.

image_slicer's People

Contributors

chughts avatar davanstrien avatar dc740 avatar landergate avatar samdobson avatar shivam13juna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image_slicer's Issues

2x8 slicer

what about 2x8 slider? horizontal and vertical slice

Joined image showing vertical and horizontal line on image

I am using image_slicer to split and join the tiff image. I split the tiff in 9 parts and after getting the prediction I joined this 9 parts into a single png image but this joined image is showing the vertical and horizontal line on the image. Below is my code that I using to split and join the tiff. Size of my tiff file is around 450 MB.

img = 'test.tif'
num_tiles = 16
tiles = image_slicer.slice(img, num_tiles)

for tile in tiles:
	name = tile.filename
	print('Processing file',name)
	out = model.predict(inp=name,out_fname=name,class_names = class_names,
	colors = class_colors,overlay_img = True,show_legends = False)
	tile.image = Image.open(name)

image = join(tiles)
image.save('join.png')

Here I upload the sample image.

ZidyP

How can I remove this lines from an image?

Image Slicing Specific Size

Use Case

Please provide a use case to help us understand your request in context

Can we set image slices to specific size? For example, I am creating 6 slices but the third slice needs to be a bit more in height as compared to other slices.

I was reading this documentation of 2018: https://readthedocs.org/projects/image-slicer/downloads/pdf/latest/ in which it's been said it will be overridable but I did not find any option which can do that or may be I missed it.

`slice-image` argument parsing bug: "num_tiles: invalid int value: ..."

The command slice-image --dir slices *.jpg 9 results in:

usage: slice-image [-d DIR] [-f FORMAT] [-h] [-v] image num_tiles
slice-image: error: argument num_tiles: invalid int value: '0012tQn.jpg'

I tried making a shell script to avoid using glob:

find $(pwd) -maxdepth 1 -type f -name '*.png' -o -name '*.jpg' |
while read filename; do
    slice-image --output slices/ $filename 9 +
done

But I still get the same error:

usage: slice-image [-d DIR] [-f FORMAT] [-h] [-v] image num_tiles
slice-image: error: argument num_tiles: invalid int value: '/home/arni/colorize/DeOldify/training_images/006HsNn.jpg'
usage: slice-image [-d DIR] [-f FORMAT] [-h] [-v] image num_tiles
slice-image: error: argument num_tiles: invalid int value: '/home/arni/colorize/DeOldify/training_images/022SLOl.jpg'
usage: slice-image [-d DIR] [-f FORMAT] [-h] [-v] image num_tiles
slice-image: error: argument num_tiles: invalid int value: '/home/arni/colorize/DeOldify/training_images/234UW9T.jpg'

Extension formet issue

As i am sliceing image into 4 parts it work fine but when i want to save in bmp formet it gives me error.
MY CODE
import image_slicer
tiles=image_slicer.slice('55.bmp', 4,save=False)
image_slicer.save_tiles(tiles, directory='~/cake_slices',prefix='slice', ext='bmp')
ERROR i am getting: TypeError: save_tiles() got an unexpected keyword argument 'ext'
For more information i am using 0.2.0 version of image_slicer with python 3.6

slice function: None type not handled for rectangular images

Hello Sam,

I have been using the image_slicer.slice() for some time now. Recently the input image dimensions changed and thus the new shape of input images have become rectangular now.
Current dimensions of new input images = 8235 * 10065 pixel (earlier the input images were square shaped with dimension in multiple of 183)
Expected output tile dimension = 183 * 183
So the number of tiles expected = 55 rows * 45 columns

I gave n=2475 (55 * 45) but the function sliced 2500 tiles of dimension 164*201 pixel, which is not the desired result in this case.

Can this (slicing the input images to a given number of tiles as rows and columns) be achieved using the slice function() ?
please suggest if its possible.

Best,
Akhil

File rename?

Try to figure out how to modify sliced file names before saving them.
image_slicer.slice(filename, 4, save=True)

Currently, this option it saves all of them in this format filename_01_01.jpg filename_01_02.jpg filename_02_01.jpg filename_02_02.jpg

Cannot find option to modify with the library.

I am looking to get this format. filename_1.jpg filename_2.jpg filename_3.jpg filename_4.jpg

does not support 16 bit images

when I use this module on 8 bit images it works fine
when I use it on 16 bit images, it raise an error
OSError: cannot write mode I;16B as PNG

Can't get it to work

import image_slicer
image_slicer.slice('face.png', 9)

This is my code.

aj@AJ:~/my files/Codes/Python$ python image_slicer.py
Traceback (most recent call last):
File "image_slicer.py", line 1, in
import image_slicer
File "/home/aj/my files/Codes/Python/image_slicer.py", line 2, in
image_slicer.slice('face.png', 9)
AttributeError: 'module' object has no attribute 'slice'

this is the error on terminal.

To split an image vertically

Great tool!

Is there a way to split an image vertically into multiple parts? (the example shows an horizontal way)

For example the original image shows 5 cats, and I want to split the image into 5 small images (each shows 1 cat)

Thank you.

Image Slicer gives reduced number of patches than expected

I am using image slicer to slice a 32x32x3 image into 8x8 patches (total of 64 patches needed).
print(Image.open(image).size) ## image is the input image and it outputs (32,32),
tiles = image_slicer.slice(image, number_tiles=64,save=False)

When I join them back, I could get only 24x24x3 image (Could visualize only 6x6 patches and the last 2x2 patches are ignored).
join = image_slicer.join(tiles)
print(join.size) ## outputs (24,24)

But the same works fine without any issue while using 128x128x3 image. I am not sure why the image size matters here and produces an unexpected output.

gif support

Use Case

Please provide a use case to help us understand your request in context

I need to slice gif, but if I try to slice gif, it converts to png.

Solution

Please describe your ideal solution

Support gif

Alternatives

Please describe any alternatives you've considered, even if you've dismissed them

Error to slice multi-channel image OSError: cannot identify image file 'XXX.tif'

Hello,

I am working with TIF satellite image files and plan to split them in smaller images of same size.

Able to split a large satellite image of size 10980*10980 in 900 equal square-shaped images using the command
tiles = image_slicer.slice(fullPath,900, save=False)
fullPath is path to a single-channel TIF image G:\\sat-data\\20150809.tif'

However when same command is given a 3-channel TIF image (of same size) as input then below error is thrown
OSError: cannot identify image file 'G:\\Merged-Sat-Imgs\\20150809-merged.tif'

Does image_slicer supports multi-channel images? Please suggest.

Thanks,
Akhil

Make test images available for download.

I noticed the filenames on your test files, but I didn't find any links to download them on your README.

Could you upload them somewhere? Or maybe even put them on this repo using git-lfs?

Thanks.

Resolution

Is it possible to define the resolution of sliced images?

Conda/pip version

Hi the version installed with pip install is version 0.3.0, as is the version in github. However, they differ. Running

tiles = image_slicer.slice('test_image.jpg', col=6, row=4, save=False)

Throws an error, but installing the github version works. This seems to be related to a commented out line in main.py, line 158, which is still in use in the version available through conda and pip.

Command-line tools: join-image

Hi there,

I am looking for the command line rutin join-image from here. However I can not find it here nor run it from terminal.
It would be nice to get back this functionality.
Or any rutin would be nice which can join the sliced images which were saved first and manipulated afterwards (in some machine learning project).

Thanks a lot!

save_tiles(format) not recognizing 'jpg'

Not specifying the format defaults to saving png tiles. If format = "png" is explicitly stated, it is also able to save png tiles. However, if format = "jpg" is stated, I get the error File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/Image.py", line 2073, in save save_handler = SAVE[format.upper()] KeyError: 'JPG'.

Please unpin Pillow

Use Case

*Please unpin Pillow as this can lead to dependency hell

Solution

requirements = ["Pillow>=7.2.0"] - tested in a fork, no issue

Alternatives

Please describe any alternatives you've considered, even if you've dismissed them

join-tiles is broken

  1. There is no open_images_in in image_slicer (EDIT: it's in helpers.py and it's called open_images).
  2. You renamed join_tiles to join not everywhere.

Why is image_slicer cropping my image?

I have an image that has a width of 150 and a height of 175. I've tried to generate very small tiles from the image as per the whole divisors of the width and height but more often than not image_slicer will not make the full amount of tiles and will crop the ones that it is missing. Is this because it cannot handle non-square rectangles?

CLI always writes pngs

The CLI always write PNGs into the source directory, even when specifying an output format. For example, slice-image original/R1.JPG 16 -f JPG -d ./tiles/ produces an series of pngs in original, and jpgs into ./tiles.

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.