1

I am making an input dataset which will have couple of thousands of images which all don't have same sizes but have same number of channels. I need to make these different images into one stack.

orders = (channels, size, size) Image sizes = (3,240,270), (3,100,170), etc 

I have tried appending it to axis of 0 and one and inserting too.

Images = append(Images, image, axis = 0) 
 File "d:/Python/advanced3DFacePointDetection/train.py", line 25, in <module> Images = np.append(Images, item, axis=0) File "C:\Users\NIK\AppData\Roaming\Python\Python37\site-packages\numpy\lib\function_base.py", line 4694, in append return concatenate((arr, values), axis=axis) ValueError: all the input array dimensions except for the concatenation axis must match exactly 

Ideal output shape is like (number of images, 3) 3 for number of channels and it contains different shapes of images after that.

6
  • Are you okay with black borders on the smaller images? Or can we resize the image without considering aspect ratio? Since you are training model using the images, it is better to resize all images to smaller size and train. Commented Jul 18, 2019 at 3:56
  • I have another dataset of X and Y points, so If I resize of do any of them my entire dataset will need adjustments. Therefore, No resizes or smaller images. Sorry. Commented Jul 18, 2019 at 3:57
  • So, you might have to pad the smaller images to match the dimension of the larger image. Check this answer out- stackoverflow.com/a/41916066/6561141 Commented Jul 18, 2019 at 4:00
  • 1
    I'll Look into it cheers mate Commented Jul 18, 2019 at 4:01
  • np.concatenate, and the related stack and append, creates a multidimensional array, for example (n_images, height, width, channels) shape. Each image in that array has to have same dimensions. There's no way around it. And it seems that most, if not all, ML packages assume a similar consistency in size. You could, of course, have a list of images with different sizes, and even make a object dtype array from that list, but what's the point if you can't train or test with such a list? Commented Jul 18, 2019 at 4:37

1 Answer 1

0

If you don't want to resize the image, choose the biggest one and padding all picture become same shape with it, i used to answer how to pad in this question: Can we resize an image from 64x64 to 256x256 without increasing the size .

When run that script in loop for all your image, create a list to save all their shape. When you want to take the original image, just take image at index x in your array and shape x in your list then crop padding image with original size.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.