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

Getting fewer images than expected #17

Open
ghost opened this issue Feb 15, 2022 · 2 comments
Open

Getting fewer images than expected #17

ghost opened this issue Feb 15, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 15, 2022

Hi,

https://drive.google.com/file/d/14eJIc8H2fa0fu6afUaJ44D1n8YKsoeSI/view?usp=sharing

I am running this code to patchify a large satellite image (above). Per the dimensions of the image (9728x3840 pixels) I am supposed to be getting 570 patches in total, however I end up with less patches (542). Any help as to what I might be missing? Link to image above...

import numpy as np
from matplotlib import pyplot as plt
from patchify import patchify
import tifffile as tiff
import cv2

img = cv2.imread("D:/patchify tests/satellite image/crop_.tif")
patches_img = patchify(img, (256,256,3), step=256)

for i in range(patches_img.shape[0]):
for j in range(patches_img.shape[1]):
single_patch_img = patches_img[i, j, 0, :, :]
if not cv2.imwrite('C:/Users/Downloads/patches/' + 'image_' +
str(i)+str(j)+'.png', single_patch_img):
raise Exception("Could not write the image")

@eliasm56
Copy link

eliasm56 commented Oct 31, 2022

I'm having the same issue. Have you figured out the cause or a solution?

@eliasm56
Copy link

eliasm56 commented Nov 1, 2022

I figured out the issue on my end. Try placing an underscore between the i and j numbers in the filename. Something like this:

# Save patches into new folder 
count = 0

for i in range(patches.shape[0]):
    for j in range(patches.shape[1]):
        count += 1
        single_img_patch = patches[i, j, :, :, :]
        cv2.imwrite(data_dir + 'patches/' + 'img_' + str(i) + '_' + str(j) + '.png', single_img_patch)
        
print(count)

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

1 participant