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

Augmentation when shift_row or shift_col is negative. #7

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

Augmentation when shift_row or shift_col is negative. #7

kota7 opened this issue Apr 27, 2017 · 5 comments

Comments

@kota7
Copy link

kota7 commented Apr 27, 2017

Hi, I find a weird behavior of Augmentation when shift_rows or shift_cols is negative.

library(OpenImageR)
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))

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

So, no change in the image at all.
It seems the function discounts shift_rows and shift_cols by 1 when it is negative. That is, it treats -1 as 0, -2 as -1, and so on.

@mlampros
Copy link
Owner

I'm sorry for the late reply,

Let me see that and If you are not in a hurry, I'll come with a solution either tomorrow or the day after tomorrow.

@mlampros
Copy link
Owner

mlampros commented Apr 30, 2017

thanks for spotting this out, it was a bug in the (image) translation function. Please test the new version of the package 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, unfortunately, I get the same result by the above code. Can you quickly copy & paste it to see if you get the same result?

Assuming that you get the same result as I do, my humble guess is that this part is a problem:

OpenImageR/src/utils.cpp

Lines 875 to 878 in 1ba1a99

if (shift_rows > 0.0 || shift_cols > 0.0) {
image = translation_mat(image, shift_rows, shift_cols, pad_shift_value);
}

It says if (shift_rows > 0.0 || shift_cols > 0.0) so shifting does not occur if both shift inputs are nonpositive. I am not sure why you have this if-clause, and any side effect occurs by removing it, though.

@mlampros
Copy link
Owner

mlampros commented May 1, 2017

I'm sorry, I totally forgot to change the inequality signs. I fixed it and I'll add some exception handling in the next few days. Please test it and let me know.

@kota7
Copy link
Author

kota7 commented May 1, 2017

Terrific. Thank you for your work!

Quick check code:

library(OpenImageR)
object <- matrix(0.5, nrow=3, ncol=4)
Augmentation(object, shift_rows=-1, padded_value=1)
Augmentation(object, shift_cols=-2, padded_value=1)
Augmentation(object, shift_row=-2, shift_cols=1, padded_value=1)
Augmentation(object, shift_row=-2, shift_cols=-3, padded_value=1)

@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