Read 4 Rotated Images from image datastore

3 次查看(过去 30 天)
I need to train a CNN using rotated images and their labels. In my image set (about 10,000 images of the same size), I rotate each image at 0, 90, 180 and 270 degrees, and label the rotated images with 0, 1, 2 and 3 respectively. The rotated images are stores in the sub-folders of names "0", "1", "2" and "3". To train the CNN, I want to feed the CNN model with 4 rotated images of the SAME image. For example, if the original image is image1, I want to get image1_0 (i.e. image1 rotated at 0 degree), image1_1 (i,e. image1 rotated 90 degrees), image1_2 (image1 rotated 180 degrees) and image1_3 (image1 rotated 270 degrees) to send them to the CNN, not randomly choosing four images from the image datastore. I'd appreciate any guidance about how to proceed.
  2 个评论
yanqi liu
yanqi liu 2022-3-1
yes,sir
if input image1_0 (i.e. image1 rotated at 0 degree), image1_1 (i,e. image1 rotated 90 degrees), image1_2 (image1 rotated 180 degrees) and image1_3 (image1 rotated 270 degrees)
now get 28*28*4 matrix
what is output? is it 1?
Yong
Yong 2022-3-1
Thank you, Yanqi.
I want to feed image1_0 (i.e. image1 rotated at 0 degree), image1_1 (i,e. image1 rotated 90 degrees), image1_2 (image1 rotated 180 degrees) and image1_3 (image1 rotated 270 degrees) , each has a label of 0, 1, 2 and 3 respectively. Image are still fed into the CNN one by one. However, I want them to be fed in small group of imageX_0, imageX_1, imageX_2, imageX_3. X can be from 1 to N, N is the number of images in the training set.
Normally, to train a CNN to output labels, training images are randomly chosen from the image datastore. In my case, because the images are generated by rotating the original images, when I train the CNN, I want them to be fed into the model in small groups of imageX_0, imageX_1, imageX_2, imageX_3.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2022-3-1
You can use the augmenter to create and rotate images on the fly. You don't need to create and save them to disk in advance.
  2 个评论
Yong
Yong 2022-3-1
I don't want to use imageDataAugmenter for the following two reasons: (1) When images are rotated 90, 180 and 270 degrees, I want to use flip and transpose operations to avoid interpolation. I am not sure how imageDataAugmenter does it. (2). The rotated images have DIFFERENT labels from the original image. The augmenter does not allow me to specify the labels for the augmented images.
Also, using augumentedImageDataStore, I can not control that the four copies of the images are fed into the CNN in a group because images are chosen randomly from the data store.
Image Analyst
Image Analyst 2022-3-1
imrotate, which the augmenter probably uses, is higly optimized. I'd bet that if the rotations are an integer multiple of 90 there is a special case to not do the full general math and just do the simplified operations like flip and transpose.
The augmenter takes an image data store and a label data store. So whatever operations are done by the augmenter are also done to the corresponding labeled image. For example if the original image is translated by 10 pixels and rotated by 30 degrees, the label image is also translated by 10 pixels and rotated by 30 degrees. Obviously it has to be this way ortherwise augmentation would not work.
I'm not sure why you want to "control" the images that are fed into the CNN. Yes it extracts some specified number of images into a minibatch randomly to speed up training. I don't know why this would be a problem. Why do you want to control which images are put into each minibatch? In the end all the images get used for training anyway.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by