Answers.Body: <p>Find the largest height and width amongst all the images. Let us call it H and W respectively. It is true that you cannot resize the images, but say if you have an image of height <code>h</code> and width <code>w</code> where <code>h &lt; H, w &lt; W</code>. To the right of the image append <code>W - w</code> number of columns and at the bottom of the image append <code>H - h</code> number of rows having some constant value (0 is okay for grey-scale and B/W images and 0 for each of the channel in case of colour images).</p>
  
  <p>In this way all the images will be of same size. Since you appending at the right and bottom of the image, the annotations will not lose its meaning in the transformed image in terms of the position and content of the text to recognised.</p>
  
  <p>You could also try <a href="https://arxiv.org/pdf/1601.06759.pdf" rel="nofollow noreferrer">pixelRNN</a> kind of ideas after you are done with DNN. RNN can handle variable length inputs and in your case it will be sequence of pixels. Here you don't need to append rows and columns to the image.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-28T06:46:26.177Z
Answers.Text: Me too thought this method. But I'm afraid that this might affect the accuracy of the network. Is that true? Correct me if I'm wrong.
Answers.UserDisplayName: Gokulakannan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-28T10:02:29.617Z
Answers.Text: You don't have much of a choice as of now frankly. Since your dataset is quite huge, the effect of padding will not affect the text recognition IMHO.
Answers.UserDisplayName: varsh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-29T06:12:29.317Z
Answers.Text: You can upvote of accept this as answer if it solves your problem. Thanks!
Answers.UserDisplayName: varsh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-28T06:41:41.257Z
Answers.LastActivityDate: 2018-06-28T06:41:41.257Z
Answers.UserDisplayName: varsh
Answers.Body: <p>Finally, I found answer for the question. In the annotations, we have X min &amp; max and Y min &amp; max of bounding box. So take the width and height of bounding box and center of bounding box relative to the image.</p>
  <p>For example, let the image dimension be <code>500*500</code>, the bounding box co-ordinates be <code>(200, 200)</code> and <code>(300, 300)</code>. So, the center of bounding box is <code>(250, 250)</code> and the height and width is <code>100</code>. Now, make it relative to image size.</p>
  <pre><code>center=(250/500,250/500)=(.5,.5)
  height=width=(100/500)=.2
  </code></pre>
  <p>If you rescale the image, with this encodings you can bring back the bounding box with new rescaled image. if you enlarge the image to 1000*1000 then,</p>
  <pre><code>center=(.5*1000,.5*1000)=(500,500)
  height=width=(.2*1000)=200
  </code></pre>
  <p>Hope this helps someone.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-11T18:04:19.990Z
Answers.LastActivityDate: 2022-04-13T08:43:42.853Z
Answers.LastEditDate: 2022-04-13T08:43:42.853Z
Answers.UserDisplayName: Gokulakannan
Body: <p>In the data-sets like coco-text and total-text, the images are of different sizes (height*width). I'm using these data sets for text detection. I want to create a DNN model for this. So the input data should be of same size. If I resize these images to a fixed size, the annotations given in the data-set, that is the location of the text in the images, will be changed.</p>
  <p>So, how do I solve this problem?</p>
  
Tags: <neural-networks><datasets><data-preprocessing><data-labelling><text-detection>
Title: How do I change the annotations of variable-size images after having resized the images to a fixed size?
UserDisplayName: Gokulakannan
ThreadText: # How do I change the annotations of variable-size images after having resized the images to a fixed size?
  
  (Asked by: username_0 on 2018-06-28)
  
  In the data-sets like coco-text and total-text, the images are of different sizes (height\*width). I'm using these data sets for text detection. I want to create a DNN model for this. So the input data should be of same size. If I resize these images to a fixed size, the annotations given in the data-set, that is the location of the text in the images, will be changed.
  
  So, how do I solve this problem?
  
  **Tags:** neural-networks, datasets, data-preprocessing, data-labelling, text-detection
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-06-28. Score: 1
  
  Find the largest height and width amongst all the images. Let us call it H and W respectively. It is true that you cannot resize the images, but say if you have an image of height `h` and width `w` where `h < H, w < W`. To the right of the image append `W - w` number of columns and at the bottom of the image append `H - h` number of rows having some constant value (0 is okay for grey-scale and B/W images and 0 for each of the channel in case of colour images).
  
  In this way all the images will be of same size. Since you appending at the right and bottom of the image, the annotations will not lose its meaning in the transformed image in terms of the position and content of the text to recognised.
  
  You could also try [pixelRNN](https://arxiv.org/pdf/1601.06759.pdf) kind of ideas after you are done with DNN. RNN can handle variable length inputs and in your case it will be sequence of pixels. Here you don't need to append rows and columns to the image.
  
  > **Comments:**
  > **username_0**: Me too thought this method. But I'm afraid that this might affect the accuracy of the network. Is that true? Correct me if I'm wrong.  
  > **username_1**: You don't have much of a choice as of now frankly. Since your dataset is quite huge, the effect of padding will not affect the text recognition IMHO.  
  > **username_1**: You can upvote of accept this as answer if it solves your problem. Thanks!  
  
  ---
  
  ### Answer by username_0 on 2018-07-11. Score: 0
  
  Finally, I found answer for the question. In the annotations, we have X min & max and Y min & max of bounding box. So take the width and height of bounding box and center of bounding box relative to the image.
  
  For example, let the image dimension be `500*500`, the bounding box co-ordinates be `(200, 200)` and `(300, 300)`. So, the center of bounding box is `(250, 250)` and the height and width is `100`. Now, make it relative to image size.
  
  ```
  center=(250/500,250/500)=(.5,.5)
  height=width=(100/500)=.2
  
  ```
  
  If you rescale the image, with this encodings you can bring back the bounding box with new rescaled image. if you enlarge the image to 1000\*1000 then,
  
  ```
  center=(.5*1000,.5*1000)=(500,500)
  height=width=(.2*1000)=200
  
  ```
  
  Hope this helps someone.
  
  
  ---
  
  