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

vignette could add library(grid) as part of instructions #28

Closed
FPI-MT opened this issue Jul 7, 2023 · 2 comments
Closed

vignette could add library(grid) as part of instructions #28

FPI-MT opened this issue Jul 7, 2023 · 2 comments

Comments

@FPI-MT
Copy link

FPI-MT commented Jul 7, 2023

My R skills are not great, so I apologize if this is too obvious and I just didn't learn the proper method.

I suggest that the vignette can be improved by indicating that the system library "grid" should be loaded.

why:
I use RStudio and it does not load 'grid' automatically. While going through the vignette at this stage:

path = file.path(getwd(), 'vignette_1', 'image2.jpg')
im = readImage(path)
thr = image_thresholding(im, thresh = 0.5)           # if the input image is 3-dimensional it will be converted internally to a matrix
imageShow(thr)

I'm hit with the following error for imageShow if I do not pre-load the grid library.

Error: Error converting object to arma::Cube<T>:
Input array must have exactly 3 dimensions.

The reason for this is that thr is a 2D matrix since rgb_2gray() is called. imageShow() then uses grid.raster. While the code used in image_thresholding() does call grid::grid.raster(), if grid isn't loaded into library, the above error is produced.

The only reason I was able to figure this out was because I stumbled across a test somewhere that said "image_thresholding" failed, but it wasn't clear why. I'm afraid I don't know where thatpage is anymore.

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

@FPI-MT
Copy link
Author

FPI-MT commented Jul 7, 2023

Seems this didn't solve my problem and the error continues.

@FPI-MT FPI-MT closed this as completed Jul 7, 2023
@mlampros mlampros reopened this Jul 8, 2023
mlampros added a commit that referenced this issue Jul 8, 2023
@mlampros
Copy link
Owner

mlampros commented Jul 8, 2023

@FPI-MT thanks for making me aware of this issue. It was actually related to an internal function that is used to check the range of values of the input image (func_chech_range()). The following should now work,

require(OpenImageR)

path = system.file("tmp_images", "1.png", package = "OpenImageR")

# displays the file using a shiny app
imageShow(path)

image = readImage(path)

# displays a 3-dimensional image (array)
imageShow(image)

thr = image_thresholding(image, thresh = 0.5)           # if the input image is 3-dimensional it will be converted internally to a matrix

# displays a 2-dimensional object (matrix)
imageShow(thr)

You can install the updated version from Github using,

remotes::install_github('mlampros/OpenImageR', dependencies = TRUE)

i'll submit the updated version to CRAN which will be available in the next days.

I'll close the issue for now feel free to re-open it in case the code does not work as expected

@mlampros mlampros closed this as completed Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants