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

Default values for shifted images by Augmentation? #6

Closed
kota7 opened this issue Apr 27, 2017 · 5 comments
Closed

Default values for shifted images by Augmentation? #6

kota7 opened this issue Apr 27, 2017 · 5 comments

Comments

@kota7
Copy link

kota7 commented Apr 27, 2017

Hi, I have a matrix representing a gray-scale image like below.
In this matrix, 0 represents black and 1 represents white.

a <- structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.157887008553284, 
0.506956425975552, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 
0.783377996402482, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0.848940934620609, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0.836092654454682, 
0.434308578980214, 0.434308578980214, 0.434308578980214, 0.434308578980214, 
0.434308578980214, 0.434308578980214, 0.434308578980214, 0.434308578980214, 
0.434308578980214, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.157887008553284, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), .Dim = c(15L, 10L))

This looks like
1

When I used Augmentation function with shift_rows or shift_cols options, I get the following.

library(OpenImageR)
Augmentation(a, shift_rows=2, shift_cols=-2)
#        [,1]  [,2] [,3]      [,4]     [,5]      [,6]      [,7] [,8]     [,9] [,10]
#  [1,]    0    1    1 1.0000000 1.000000 0.8489409 0.8360927    1 1.000000     1
#  [2,]    0    1    1 0.1578870 0.000000 0.0000000 0.4343086    1 1.000000     1
#  [3,]    0    1    1 0.5069564 0.783378 0.0000000 0.4343086    1 1.000000     1
#  [4,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
#  [5,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
#  [6,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
#  [7,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
#  [8,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
#  [9,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
# [10,]    0    1    1 1.0000000 1.000000 0.0000000 0.4343086    1 1.000000     1
# [11,]    0    1    1 0.0000000 0.000000 0.0000000 0.0000000    0 0.157887     1
# [12,]    0    1    1 1.0000000 1.000000 1.0000000 1.0000000    1 1.000000     1
# [13,]    0    1    1 1.0000000 1.000000 1.0000000 1.0000000    1 1.000000     1
# [14,]    0    0    0 0.0000000 0.000000 0.0000000 0.0000000    0 0.000000     0
# [15,]    0    0    0 0.0000000 0.000000 0.0000000 0.0000000    0 0.000000     0

This looks like below.
1b

So, the padded value is always 0, where I want to use 1 to fill and I could not find a way to choose it.
It would be great if I can freely chose the default value to be filled in.

Thanks.

@mlampros
Copy link
Owner

I'm sorry for the late reply,

If you are not in a hurry, I'll come with a fix either tomorrow or the day after tomorrow.

@mlampros
Copy link
Owner

I added the padded_value parameter to both the Augmentation and the translation functions. Besides 0 it can take posiitve, negative or float values. Please test the new version using devtools::install_github('mlampros/OpenImageR') (it will take some time till the new version of the package is on CRAN) and let me know.

@kota7
Copy link
Author

kota7 commented Apr 30, 2017

Hi, thanks for your quick response! It now works good for my case (matrix image).

I have a suggestion for 3d-array case.

library(OpenImageR)
object <- array(1, dim = c(10, 10, 3))
Augmentation(object, shift_rows=2, padded_value=0.5)

The code above pads a certain value into all three dimension.
Assuming each dimension corresponds to R,G,B, this means we can pad black, white, or any gray colors.

Some may wish to pad by red, i.e. (1,0,0), but the code below does not work.

Augmentation(object, shift_rows=2, padded_value=c(1,0,0))
#Error in augment_transf_array(image, flip_mode, crop_height, crop_width,  : 
#  expecting a single value

Allowing padded values of vector of size equal to the channel dimension size can be a good enhancement.

@mlampros
Copy link
Owner

mlampros commented May 1, 2017

I added the functionality that you suggested in both translation and Augmentation functions. The padded_value parameter can be either a numeric value (of length 1) or a numeric vector (of length equal to the dimensions of the array). I'll add exception handling in the next few days. Please test it and let me know.

@kota7
Copy link
Author

kota7 commented May 1, 2017

Beautiful. It works great.

Quick check I have run:

library(OpenImageR)
object <- matrix(1, nrow=2, ncol=5)
Augmentation(object, shift_cols=1, padded_value=-5)

object <- array(1, dim = c(4, 2, 3))
Augmentation(object, shift_rows=1, padded_value=0.5)
Augmentation(object, shift_rows=1, padded_value=c(3,4,5))

@kota7 kota7 closed this as completed May 1, 2017
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

2 participants