├── .Rbuildignore ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ └── issue_template.md └── workflows │ ├── docker-image.yml │ ├── issue.yml │ ├── stale-actions.yml │ └── tic.yml ├── .gitignore ├── DESCRIPTION ├── Dockerfile ├── NAMESPACE ├── NEWS.md ├── R ├── OpenImageR.R ├── RcppExports.R ├── gabor_feature_extraction.R ├── hash_functions.R ├── hog_features_rscript.R ├── launcher_shiny.R ├── open_image_rscript.R ├── read_image.R ├── shiny_rscript.R ├── superpixels.R ├── warp_affine.R └── write_image.R ├── README.md ├── inst ├── CITATION ├── COPYRIGHTS ├── documentation │ └── AffineTransformation.pdf ├── include │ ├── OpenImageRheader.h │ ├── SLIC.h │ └── SLICO.h ├── shiny_app │ ├── server.R │ └── ui.R └── tmp_images │ ├── 1.png │ ├── 2.jpg │ ├── 3.jpeg │ ├── car.png │ ├── landscape.jpg │ ├── same_type │ ├── 1.png │ ├── 10.png │ ├── 4.png │ ├── 5.png │ └── 8.png │ └── slic_im.png ├── man ├── Augmentation.Rd ├── GaborFeatureExtract.Rd ├── HOG.Rd ├── HOG_apply.Rd ├── List_2_Array.Rd ├── MinMaxObject.Rd ├── NormalizeObject.Rd ├── RGB_to_HSV.Rd ├── RGB_to_Lab.Rd ├── ZCAwhiten.Rd ├── average_hash.Rd ├── convolution.Rd ├── cropImage.Rd ├── crop_image_secondary.Rd ├── delationErosion.Rd ├── dhash.Rd ├── dilationErosion.Rd ├── down_sample_image.Rd ├── edge_detection.Rd ├── flipImage.Rd ├── func_chech_range.Rd ├── func_transform.Rd ├── gamma_correction.Rd ├── gaussian_kernel.Rd ├── getAffineTransform.Rd ├── hash_apply.Rd ├── imageShow.Rd ├── image_thresholding.Rd ├── invariant_hash.Rd ├── laplacian_kernels.Rd ├── load_binary.Rd ├── norm_matrix_range.Rd ├── padding.Rd ├── phash.Rd ├── readImage.Rd ├── resizeImage.Rd ├── rgb_2gray.Rd ├── rotateFixed.Rd ├── rotateImage.Rd ├── runUI.Rd ├── sec_gaus_bl.Rd ├── sec_resiz_array.Rd ├── superpixel_bbox.Rd ├── superpixel_bbox_subset.Rd ├── superpixels.Rd ├── switch_filter.Rd ├── switch_hashing.Rd ├── switch_invariant.Rd ├── translation.Rd ├── uniform_filter.Rd ├── verify_image_extension.Rd ├── warpAffine.Rd └── writeImage.Rd ├── src ├── Makevars ├── Makevars.win ├── RcppExports.cpp ├── extract_inst_folder_headers.cpp └── init.c ├── tests ├── testthat.R └── testthat │ ├── image_files │ ├── 1.png │ ├── 2.jpg │ ├── 3.jpeg │ ├── 4.tiff │ ├── HOG_apply_folder │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 4.png │ │ ├── 5.png │ │ └── 8.png │ └── invalid_image │ │ └── invalid_image.inv │ ├── test-augmentation.R │ ├── test-crop_image.R │ ├── test-delation_erosion.R │ ├── test-down_sample_blur.R │ ├── test-edge_detection.R │ ├── test-flip_zca_image.R │ ├── test-gabor.R │ ├── test-gamma_threshold.R │ ├── test-gaussian_kernel.R │ ├── test-hash_functionsR.R │ ├── test-hog_features.R │ ├── test-laplacian_kernels.R │ ├── test-list_to_array_translation.R │ ├── test-norm_matrix_range.R │ ├── test-normalize_min_max.R │ ├── test-read_image.R │ ├── test-resize_nearest.R │ ├── test-rgb_to_gray.R │ ├── test-rotate.R │ ├── test-shiny_apps.R │ ├── test-superpixels.R │ ├── test-uniform_filter_convolution.R │ ├── test-warp_affine.R │ └── test-write_image.R ├── tic.R └── vignettes ├── Gabor_Feature_Extraction.Rmd ├── Image_segmentation_superpixels_clustering.Rmd ├── TEST_hash ├── 2_1.png ├── 2_2.png ├── 2_3.png ├── 4_1.png ├── 4_2.png ├── 4_3.png ├── 5_1.png ├── 5_2.png ├── 5_3.png ├── 8_1.png ├── 8_2.png ├── 8_3.png ├── 9_1.png ├── 9_2.png └── 9_3.png ├── The_OpenImageR_package.Rmd ├── Warp_Affine.Rmd ├── vignette_1 ├── image1.jpeg ├── image2.jpg ├── view1.jpg ├── view2.jpg └── view3.jpg ├── vignette_2 ├── car.png ├── gabor_car.png ├── gabor_car_thresholding.png └── gabor_filter_bank.png └── vignette_3 ├── BSR_bsds500_image.jpg ├── BSR_bsds500_segmentation.png ├── airplane.jpg ├── im_masks.png ├── segment_AP.png ├── segment_kmeans.png ├── segment_mbkm.png └── slic_vs_slico.png /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Dockerfile$ 2 | ^.git$ 3 | ^.github$ 4 | ^\.ccache$ 5 | ^\.github$ 6 | ^tic\.R$ 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | # For more info see: https://docs.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser 2 | 3 | blank_issues_enabled: true 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report or feature request 3 | about: Describe a bug you've encountered or make a case for a new feature 4 | --- 5 | 6 | Please briefly describe your problem and what output you expect. If you have a question, you also have the option of (but I'm flexible if it's not too complicated) 7 | 8 | Please include a minimal reproducible example 9 | 10 | Please give a brief description of the problem 11 | 12 | Please add your Operating System (e.g., Windows10, Macintosh, Linux) and the R version that you use (e.g., 3.6.2) 13 | 14 | If my package uses Python (via 'reticulate') then please add also the Python version (e.g., Python 3.8) and the 'reticulate' version (e.g., 1.18.0) 15 | -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | 2 | #.......................................................................................................... 3 | # build, push and cache the docker image. I have to adjust the following in case of a different repository: 4 | # - I have to add the 'BUILD_DATE' arg in the Dockerfile 5 | # - I have to create a DOCKER_PASSWORD (use the docker token) in the 'Settings' tab of the repository 6 | # References: 7 | # - https://github.com/mlampros/IceSat2R/blob/master/.github/workflows/docker_image.yml 8 | # - https://github.com/orgs/community/discussions/25768#discussioncomment-3249184 9 | #.......................................................................................................... 10 | 11 | on: 12 | push: 13 | branches: [main, master] 14 | pull_request: 15 | branches: [main, master] 16 | 17 | name: docker_img 18 | 19 | jobs: 20 | build: 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - id: string 25 | uses: ASzc/change-string-case-action@v1 26 | with: 27 | string: ${{ github.event.repository.name }} 28 | 29 | - name: Check Out Repo 30 | uses: actions/checkout@v2 31 | 32 | - name: Login to Docker Hub 33 | uses: docker/login-action@v2 34 | with: 35 | username: ${{ github.repository_owner }} 36 | password: ${{ secrets.DOCKER_PASSWORD }} 37 | 38 | - name: Set up Docker Buildx 39 | uses: docker/setup-buildx-action@v1 40 | 41 | - name: Build and push 42 | uses: docker/build-push-action@v2 43 | with: 44 | context: ./ 45 | build-args: BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" 46 | file: ./Dockerfile 47 | builder: ${{ steps.buildx.outputs.name }} 48 | push: true 49 | tags: ${{ github.repository_owner }}/${{ steps.string.outputs.lowercase }}:rstudiodev 50 | cache-from: type=registry,ref=${{ github.repository_owner }}/${{ steps.string.outputs.lowercase }}:buildcache 51 | cache-to: type=registry,ref=${{ github.repository_owner }}/${{ steps.string.outputs.lowercase }}:buildcache,mode=max 52 | -------------------------------------------------------------------------------- /.github/workflows/issue.yml: -------------------------------------------------------------------------------- 1 | # For more info see: https://github.com/Renato66/auto-label 2 | # for the 'secrets.GITHUB_TOKEN' see: https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret 3 | 4 | name: Labeling new issue 5 | on: 6 | issues: 7 | types: ['opened'] 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: Renato66/auto-label@v2 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | ignore-comments: true 16 | labels-synonyms: '{"bug":["error","need fix","not working"],"enhancement":["upgrade"],"question":["help","how can i"]}' 17 | labels-not-allowed: '["documentation","duplicate","good first issue","help wanted","invalid"]' 18 | default-labels: '["triage"]' 19 | -------------------------------------------------------------------------------- /.github/workflows/stale-actions.yml: -------------------------------------------------------------------------------- 1 | # for the 'secrets.GITHUB_TOKEN' see: https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret 2 | 3 | name: "Mark or close stale issues and PRs" 4 | 5 | on: 6 | schedule: 7 | - cron: "00 * * * *" 8 | 9 | jobs: 10 | stale: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/stale@v3 14 | with: 15 | repo-token: ${{ secrets.GITHUB_TOKEN }} 16 | days-before-stale: 12 17 | days-before-close: 7 18 | stale-issue-message: "This is Robo-lampros because the Human-lampros is lazy. This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs. Feel free to re-open a closed issue and the Human-lampros will respond." 19 | stale-pr-message: "This is Robo-lampros because the Human-lampros is lazy. This PR has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs." 20 | close-issue-message: "This issue was automatically closed because of being stale. Feel free to re-open a closed issue and the Human-lampros will respond." 21 | close-pr-message: "This PR was automatically closed because of being stale." 22 | stale-pr-label: "stale" 23 | stale-issue-label: "stale" 24 | exempt-issue-labels: "bug,enhancement,pinned,security,pending,work_in_progress" 25 | exempt-pr-labels: "bug,enhancement,pinned,security,pending,work_in_progress" 26 | -------------------------------------------------------------------------------- /.github/workflows/tic.yml: -------------------------------------------------------------------------------- 1 | ## tic GitHub Actions template: linux-macos-windows-deploy 2 | ## revision date: 2020-12-11 3 | on: 4 | workflow_dispatch: 5 | push: 6 | pull_request: 7 | # for now, CRON jobs only run on the default branch of the repo (i.e. usually on master) 8 | schedule: 9 | # * is a special character in YAML so you have to quote this string 10 | - cron: "0 4 * * *" 11 | 12 | name: tic 13 | 14 | jobs: 15 | all: 16 | runs-on: ${{ matrix.config.os }} 17 | 18 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | config: 24 | # use a different tic template type if you do not want to build on all listed platforms 25 | - { os: windows-latest, r: "release" } 26 | - { os: macOS-latest, r: "release", pkgdown: "true", latex: "true" } 27 | - { os: ubuntu-latest, r: "devel" } 28 | - { os: ubuntu-latest, r: "release" } 29 | 30 | env: 31 | # otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries 32 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 33 | CRAN: ${{ matrix.config.cran }} 34 | # make sure to run `tic::use_ghactions_deploy()` to set up deployment 35 | TIC_DEPLOY_KEY: ${{ secrets.TIC_DEPLOY_KEY }} 36 | # prevent rgl issues because no X11 display is available 37 | RGL_USE_NULL: true 38 | # if you use bookdown or blogdown, replace "PKGDOWN" by the respective 39 | # capitalized term. This also might need to be done in tic.R 40 | BUILD_PKGDOWN: ${{ matrix.config.pkgdown }} 41 | # macOS >= 10.15.4 linking 42 | SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk 43 | # use GITHUB_TOKEN from GitHub to workaround rate limits in {remotes} 44 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 45 | 46 | steps: 47 | - uses: actions/checkout@v3 48 | 49 | - uses: r-lib/actions/setup-r@v2 50 | with: 51 | r-version: ${{ matrix.config.r }} 52 | Ncpus: 4 53 | 54 | # LaTeX. Installation time: 55 | # Linux: ~ 1 min 56 | # macOS: ~ 1 min 30s 57 | # Windows: never finishes 58 | - uses: r-lib/actions/setup-tinytex@v2 59 | if: matrix.config.latex == 'true' 60 | 61 | - uses: r-lib/actions/setup-pandoc@v2 62 | 63 | # set date/week for use in cache creation 64 | # https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970 65 | # - cache R packages daily 66 | - name: "[Cache] Prepare daily timestamp for cache" 67 | if: runner.os != 'Windows' 68 | id: date 69 | run: echo "::set-output name=date::$(date '+%d-%m')" 70 | 71 | - name: "[Cache] Cache R packages" 72 | if: runner.os != 'Windows' 73 | uses: pat-s/always-upload-cache@v2.1.3 74 | with: 75 | path: ${{ env.R_LIBS_USER }} 76 | key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}} 77 | restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}} 78 | 79 | # for some strange Windows reason this step and the next one need to be decoupled 80 | - name: "[Stage] Prepare" 81 | run: | 82 | Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')" 83 | Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')" 84 | 85 | - name: "[Stage] [Linux] Install curl and libgit2" 86 | if: runner.os == 'Linux' 87 | run: sudo apt install libcurl4-openssl-dev libgit2-dev 88 | 89 | - name: "[Stage] [macOS] Install libgit2" 90 | if: runner.os == 'macOS' 91 | run: brew install libgit2 92 | 93 | - name: "[Stage] [macOS] Install system libs for pkgdown" 94 | if: runner.os == 'macOS' && matrix.config.pkgdown != '' 95 | run: brew install harfbuzz fribidi 96 | 97 | - name: "[Stage] [Linux] Install system libs for pkgdown" 98 | if: runner.os == 'Linux' && matrix.config.pkgdown != '' 99 | run: sudo apt install libharfbuzz-dev libfribidi-dev 100 | 101 | - name: "[Stage] Install" 102 | if: matrix.config.os != 'macOS-latest' || matrix.config.r != 'devel' 103 | run: Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" 104 | 105 | # macOS devel needs its own stage because we need to work with an option to suppress the usage of binaries 106 | - name: "[Stage] Prepare & Install (macOS-devel)" 107 | if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'devel' 108 | run: | 109 | echo -e 'options(Ncpus = 4, pkgType = "source", repos = structure(c(CRAN = "https://cloud.r-project.org/")))' > $HOME/.Rprofile 110 | Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()" 111 | 112 | - name: "[Stage] Script" 113 | run: Rscript -e 'tic::script()' 114 | 115 | - name: "[Stage] After Success" 116 | if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release' 117 | run: Rscript -e "tic::after_success()" 118 | 119 | - name: "[Stage] Upload R CMD check artifacts" 120 | if: failure() 121 | uses: actions/upload-artifact@v2.2.1 122 | with: 123 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 124 | path: check 125 | - name: "[Stage] Before Deploy" 126 | run: | 127 | Rscript -e "tic::before_deploy()" 128 | 129 | - name: "[Stage] Deploy" 130 | run: Rscript -e "tic::deploy()" 131 | 132 | - name: "[Stage] After Deploy" 133 | run: Rscript -e "tic::after_deploy()" 134 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | docs/ 2 | .Rhistory 3 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: OpenImageR 2 | Type: Package 3 | Title: An Image Processing Toolkit 4 | Version: 1.3.0 5 | Date: 2023-07-08 6 | Authors@R: c( person("Lampros", "Mouselimis", email = "mouselimislampros@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "https://orcid.org/0000-0002-8024-1546")), person("Sight", "Machine", role = "cph", comment = "findHOGFeatures function of the SimpleCV computer vision platform"), person("Johannes", "Buchner", role = "cph", comment = "average_hash, dhash and phash functions of the ImageHash python library"), person("Mohammad", "Haghighat", email = "haghighat@ieee.org", role = "cph", comment = "Gabor Feature Extraction"), person("Radhakrishna", "Achanta", email = "Radhakrishna.Achanta@epfl.ch", role = "cph", comment = "Author of the C++ code of the SLIC and SLICO algorithms (for commercial use please contact the author)"), person("Oleh", "Onyshchak", role = "cph", comment = "Author of the Python code of the WarpAffine function") ) 7 | Maintainer: Lampros Mouselimis 8 | BugReports: https://github.com/mlampros/OpenImageR/issues 9 | URL: https://github.com/mlampros/OpenImageR 10 | Description: Incorporates functions for image preprocessing, filtering and image recognition. The package takes advantage of 'RcppArmadillo' to speed up computationally intensive functions. The histogram of oriented gradients descriptor is a modification of the 'findHOGFeatures' function of the 'SimpleCV' computer vision platform, the average_hash(), dhash() and phash() functions are based on the 'ImageHash' python library. The Gabor Feature Extraction functions are based on 'Matlab' code of the paper, "CloudID: Trustworthy cloud-based and cross-enterprise biometric identification" by M. Haghighat, S. Zonouz, M. Abdel-Mottaleb, Expert Systems with Applications, vol. 42, no. 21, pp. 7905-7916, 2015, . The 'SLIC' and 'SLICO' superpixel algorithms were explained in detail in (i) "SLIC Superpixels Compared to State-of-the-art Superpixel Methods", Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Suesstrunk, IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 34, num. 11, p. 2274-2282, May 2012, and (ii) "SLIC Superpixels", Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Suesstrunk, EPFL Technical Report no. 149300, June 2010. 11 | License: GPL-3 12 | Encoding: UTF-8 13 | Copyright: inst/COPYRIGHTS 14 | SystemRequirements: libarmadillo: apt-get install -y libarmadillo-dev (deb), libblas: apt-get install -y libblas-dev (deb), liblapack: apt-get install -y liblapack-dev (deb), libarpack++2: apt-get install -y libarpack++2-dev (deb), gfortran: apt-get install -y gfortran (deb), libjpeg-dev: apt-get install -y libjpeg-dev (deb), libpng-dev: apt-get install -y libpng-dev (deb), libfftw3-dev: apt-get install -y libfftw3-dev (deb), libtiff5-dev: apt-get install -y libtiff5-dev (deb) 15 | Depends: 16 | R(>= 3.2.3) 17 | Imports: 18 | Rcpp (>= 0.12.17), 19 | graphics, 20 | grDevices, 21 | grid, 22 | shiny, 23 | jpeg, 24 | png, 25 | tiff, 26 | R6, 27 | lifecycle, 28 | tools 29 | LinkingTo: 30 | Rcpp, 31 | RcppArmadillo (>= 0.8.0) 32 | Suggests: 33 | testthat, 34 | knitr, 35 | rmarkdown, 36 | covr 37 | RoxygenNote: 7.2.3 38 | VignetteBuilder: knitr 39 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/rstudio:devel 2 | 3 | LABEL maintainer='Lampros Mouselimis' 4 | 5 | RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update && \ 6 | apt-get install -y libfftw3-dev libpng-dev libssl-dev pandoc pandoc-citeproc make libcurl4-openssl-dev && \ 7 | apt-get install -y sudo && \ 8 | apt-get install -y libarmadillo-dev && \ 9 | apt-get install -y libblas-dev && \ 10 | apt-get install -y liblapack-dev && \ 11 | apt-get install -y libarpack++2-dev && \ 12 | apt-get install -y gfortran && \ 13 | apt-get install -y libjpeg-dev && \ 14 | apt-get install -y libpng-dev && \ 15 | apt-get install -y libfftw3-dev && \ 16 | apt-get install -y libtiff5-dev && \ 17 | apt-get install -y libxml2-dev libssh2-1-dev zlib1g-dev git-core && \ 18 | R -e "install.packages('devtools', dependencies = TRUE, repos = 'https://cloud.r-project.org/')" && \ 19 | R -e "install.packages(c( 'Rcpp', 'graphics', 'grDevices', 'grid', 'shiny', 'jpeg', 'png', 'tiff', 'R6', 'RcppArmadillo', 'testthat', 'knitr', 'rmarkdown', 'covr', 'tools', 'remotes' ), repos = 'https://cloud.r-project.org/' )" 20 | 21 | ADD http://www.random.org/strings/?num=10&len=8&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new uuid 22 | ARG BUILD_DATE 23 | 24 | RUN echo "$BUILD_DATE" 25 | RUN R -e "remotes::install_github('mlampros/OpenImageR', upgrade = 'never', dependencies = FALSE, repos = 'https://cloud.r-project.org/')" && \ 26 | apt-get autoremove -y && \ 27 | apt-get clean 28 | 29 | ENV USER rstudio 30 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(Augmentation) 4 | export(GaborFeatureExtract) 5 | export(HOG) 6 | export(HOG_apply) 7 | export(List_2_Array) 8 | export(MinMaxObject) 9 | export(NormalizeObject) 10 | export(RGB_to_HSV) 11 | export(RGB_to_Lab) 12 | export(ZCAwhiten) 13 | export(average_hash) 14 | export(convolution) 15 | export(cropImage) 16 | export(delationErosion) 17 | export(dhash) 18 | export(dilationErosion) 19 | export(down_sample_image) 20 | export(edge_detection) 21 | export(flipImage) 22 | export(gamma_correction) 23 | export(getAffineTransform) 24 | export(hash_apply) 25 | export(imageShow) 26 | export(image_thresholding) 27 | export(invariant_hash) 28 | export(load_binary) 29 | export(norm_matrix_range) 30 | export(padding) 31 | export(phash) 32 | export(readImage) 33 | export(resizeImage) 34 | export(rgb_2gray) 35 | export(rotateFixed) 36 | export(rotateImage) 37 | export(superpixel_bbox) 38 | export(superpixel_bbox_subset) 39 | export(superpixels) 40 | export(translation) 41 | export(uniform_filter) 42 | export(verify_image_extension) 43 | export(warpAffine) 44 | export(writeImage) 45 | import(shiny) 46 | importFrom(R6,R6Class) 47 | importFrom(Rcpp,evalCpp) 48 | importFrom(graphics,image) 49 | importFrom(graphics,par) 50 | importFrom(graphics,title) 51 | importFrom(grid,grid.raster) 52 | importFrom(jpeg,readJPEG) 53 | importFrom(jpeg,writeJPEG) 54 | importFrom(lifecycle,badge) 55 | importFrom(lifecycle,deprecate_warn) 56 | importFrom(png,readPNG) 57 | importFrom(png,writePNG) 58 | importFrom(shiny,runApp) 59 | importFrom(tiff,readTIFF) 60 | importFrom(tiff,writeTIFF) 61 | importFrom(tools,file_ext) 62 | useDynLib(OpenImageR, .registration = TRUE) 63 | -------------------------------------------------------------------------------- /R/OpenImageR.R: -------------------------------------------------------------------------------- 1 | #' @useDynLib OpenImageR, .registration = TRUE 2 | #' @importFrom Rcpp evalCpp 3 | #' @import shiny 4 | #' @importFrom lifecycle badge deprecate_warn 5 | NULL 6 | -------------------------------------------------------------------------------- /R/hog_features_rscript.R: -------------------------------------------------------------------------------- 1 | 2 | #' calculate the HOG (Histogram of oriented gradients) for an image 3 | #' 4 | #' 5 | #' The function is a modification of the 'findHOGFeatures' function of the SimpleCV package [ please consult the COPYRIGHT file ] 6 | #' The function takes either an RGB (it will be converted to gray) or a gray image and returns a vector of the HOG descriptors. 7 | #' The main purpose of the function is to create a vector of features, which can be used in classification tasks. 8 | #' 9 | #' @param image matrix or 3-dimensional array where the third dimension is equal to 3 10 | #' @param cells the number of divisions ( cells ) 11 | #' @param orientations number of orientation bins 12 | #' @return a numeric vector 13 | #' @details 14 | #' This function takes either a matrix, a data frame or a 3-dimensional array (where the third dimension is equal to 3) and returns a vector with the HOG-descriptors (histogram of oriented gradients). 15 | #' @export 16 | #' @examples 17 | #' 18 | #' \dontrun{ 19 | #' 20 | #' path = system.file("tmp_images", "1.png", package = "OpenImageR") 21 | #' 22 | #' image = readImage(path) 23 | #' 24 | #' res = HOG(image, cells = 3, orientations = 6) 25 | #' } 26 | 27 | 28 | HOG = function(image, cells = 3, orientations = 6) { 29 | 30 | if (inherits(image, 'data.frame')) image = as.matrix(image) 31 | 32 | if (inherits(image, 'matrix')) { 33 | 34 | res = hog_cpp(image, n_divs = cells, n_bins = orientations) 35 | } 36 | else if (all(c(inherits(image, 'array'), !is.na(dim(image)[3]), dim(image)[3] == 3))) { 37 | 38 | image = rgb_2gray(image) 39 | res = hog_cpp(image, n_divs = cells, n_bins = orientations) 40 | } 41 | else { 42 | 43 | stop('valid types of input are matrix, data frame and 3-dimensional array where the third dimension is equal to 3') 44 | } 45 | 46 | return(as.vector(res)) 47 | } 48 | 49 | 50 | 51 | #' secondary function for HOG_apply 52 | #' 53 | #' @importFrom png readPNG 54 | #' @importFrom jpeg readJPEG 55 | #' @importFrom tiff readTIFF 56 | #' 57 | #' @keywords internal 58 | 59 | 60 | func_transform = function(image, folder_path, flag_type, RGB_2gray = F) { 61 | 62 | if (flag_type == "png") { 63 | 64 | img = png::readPNG(paste(folder_path, image, sep = ""))} 65 | 66 | else if (flag_type == "jpg" || flag_type == "jpeg") { 67 | 68 | img = jpeg::readJPEG(paste(folder_path, image, sep = ""))} 69 | 70 | else if (flag_type %in% c("tiff", "tif", "TIFF", "TIF")) { 71 | 72 | img = tiff::readTIFF(paste(folder_path, image, sep = ""))} 73 | 74 | else { 75 | 76 | stop('supported image types are .png, .jpeg, .jpg, .tiff (or .tif, .TIFF, .TIF)') 77 | } 78 | 79 | if (RGB_2gray) { 80 | 81 | img = rgb_2gray(img) 82 | } 83 | 84 | return(img) 85 | } 86 | 87 | 88 | 89 | 90 | #' calculate the HOG (Histogram of oriented gradients) for a matrix, array or a folder of images 91 | #' 92 | #' @param object a matrix, a data frame, a 3-dimensional array (where the third dimension is equal to 3) or a path to a folder of files (images) 93 | #' @param cells the number of divisions ( cells ) 94 | #' @param orientations number of orientation bins 95 | #' @param rows a value specifying the number of rows of each image-row of the matrix (required if object is a matrix) 96 | #' @param columns a value specifying the number of columns of each image-row of the matrix (required if object is a matrix) 97 | #' @param threads the number of parallel cores to use 98 | #' @return If the input is a matrix, data frame or array it returns a matrix of the hog descriptors. If the input is a path to a folder it returns a list of length 2, 99 | #' the 1st sublist is a vector with the names of the image files (the order of the files in the vector corresponds to the order of the rows of the output matrix), 100 | #' the 2nd sublist is the matrix of the hog descriptors. 101 | #' @details 102 | #' This function takes as input either a matrix, a data frame, a 3-dimensional array (where the third dimension is equal to 3) or a character path to a folder of files (images). It returns the HOG-descriptors 103 | #' (histogram of oriented gradients) for each row (if matrix or data frame), for each array-slice (if array) or for each file (if path to a folder of images). 104 | #' @export 105 | #' @examples 106 | #' 107 | #' \dontrun{ 108 | #' 109 | #' MATR = matrix(runif(75), ncol = 25, nrow = 5) 110 | #' 111 | #' res = HOG_apply(MATR, cells = 3, orientations = 5, rows = 5, columns = 5, threads = 1) 112 | #' 113 | #' 114 | #' ARRAY = array(5, dim = c(10, 10, 3)) 115 | #' 116 | #' res = HOG_apply(ARRAY, cells = 3, orientations = 6, threads = 1) 117 | #' 118 | #' 119 | #' FOLDER_path = paste0(system.file("tmp_images", "same_type", package = "OpenImageR"), '/') 120 | #' 121 | #' res = HOG_apply(FOLDER_path, cells = 3, orientations = 6, threads = 1) 122 | #' } 123 | 124 | 125 | HOG_apply = function(object, cells = 3, orientations = 6, rows = NULL, columns = NULL, threads = 1) { 126 | 127 | if (threads < 1) stop('threads should be at least 1') 128 | if (inherits(object, 'matrix') && (is.null(columns) || is.null(rows))) stop('give number of rows and columns of the matrix') 129 | if (cells < 1 || orientations < 1) stop("The 'cells' and 'orientations' arguments should be greater than 0") 130 | if (inherits(object, 'data.frame')) object = as.matrix(object) 131 | 132 | try_err_files = inherits(tryCatch(normalizePath(object, mustWork = T), error = function(e) e), "error") 133 | 134 | start = Sys.time() 135 | 136 | if (inherits(object, "character") && try_err_files == F) { 137 | 138 | str_SPL = strsplit(object, "")[[1]] 139 | 140 | if (!str_SPL[nchar(object)] %in% c("/", "\\")) stop('the folder path should end in slash') 141 | 142 | lst_files = list.files(object) 143 | 144 | flag_type = unlist(strsplit(lst_files[1], '[.]'))[length(unlist(strsplit(lst_files[1], '[.]')))] 145 | 146 | if (!flag_type %in% c("png", "jpg", "jpeg", "tiff", "tif", "TIFF", "TIF")) stop('supported image types are .png, .jpeg, .jpg, .tiff (or .tif, .TIFF, .TIF)') 147 | 148 | tmp_lst = lapply(1:length(lst_files), function(y) func_transform(lst_files[y], object, flag_type, T)) 149 | 150 | conv_to_array = list_2array_convert(tmp_lst) 151 | 152 | tmp_out = HOG_array(conv_to_array, n_divs = cells, n_bins = orientations, threads = threads) 153 | 154 | out = list(files = lst_files, hog = tmp_out)} 155 | 156 | else if (inherits(object, 'matrix') && try_err_files == T) { 157 | 158 | if (length(object[1, ]) != columns * rows) stop('rows * columns must be equal to the length of each row') 159 | 160 | out = HOG_matrix(object, columns, rows, n_divs = cells, n_bins = orientations, threads = threads)} 161 | 162 | else if (inherits(object, 'array') && try_err_files == T) { 163 | 164 | out = HOG_array(object, n_divs = cells, n_bins = orientations, threads = threads)} 165 | 166 | else { 167 | 168 | stop('valid object types are matrix, data.frame, array or a character path to folder-of-files (images)') 169 | } 170 | 171 | end = Sys.time() 172 | 173 | t = end - start 174 | 175 | cat('\n'); cat('time to complete :', t, attributes(t)$units, '\n'); cat('\n'); 176 | 177 | return(out) 178 | } 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /R/launcher_shiny.R: -------------------------------------------------------------------------------- 1 | 2 | #' launcher for the shiny application 3 | #' 4 | #' @importFrom shiny runApp 5 | #' 6 | #' @keywords internal 7 | 8 | runUI <- function () { 9 | 10 | shiny::runApp( system.file('shiny_app', package = 'OpenImageR') ) 11 | } 12 | -------------------------------------------------------------------------------- /R/read_image.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Verify that the input image extension is valid 4 | #' 5 | #' @param image_path a character string specifying the path to the saved image 6 | #' @param regex_img a character string specifying the regex used to verify if the image extension is valid 7 | #' @return either the image path extension or an error 8 | #' @details 9 | #' 10 | #' The OpenImageR package uses the 'readPNG', 'readJPEG' and 'readTIFF' R packages in the background. Thus, only image file path 11 | #' extensions that can be processed from these R packages should be used as input to the 'readImage' function 12 | #' 13 | #' @importFrom tools file_ext 14 | #' 15 | #' @references 16 | #' 17 | #' https://github.com/mlampros/OpenImageR/issues/25 18 | #' 19 | #' @export 20 | #' @examples 21 | #' 22 | #' vec_img_ext = c('png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'tif', 'TIF', 'tiff', 'TIFF') 23 | #' 24 | #' vec_valid = sapply(vec_img_ext, function(x) { 25 | #' ext_iter = paste(c('example_image', x), collapse = '.') 26 | #' verify_image_extension(image_path = ext_iter) 27 | #' }) 28 | #' 29 | #' all(vec_img_ext == vec_valid) 30 | 31 | 32 | verify_image_extension = function(image_path, 33 | regex_img = "jpe?g|png|tif$|tiff$") { 34 | 35 | img_ext = tools::file_ext(image_path) 36 | img_valid = grepl(x = img_ext, pattern = regex_img, ignore.case = TRUE) 37 | if (img_valid) { 38 | return(img_ext) 39 | } 40 | else { 41 | stop("The input image path does not have a file extension OR is not a supported image path extension of the OpenImageR package!", call. = F) 42 | } 43 | } 44 | 45 | 46 | #' this function reads various types of images 47 | #' 48 | #' Reads images of type .png, .jpeg, .jpg, .tiff 49 | #' 50 | #' @param path a character string specifying the path to the saved image 51 | #' @param ... further arguments for the readPNG, readJPEG and readTIFF functions 52 | #' @return the image in a matrix or array form 53 | #' @details 54 | #' This function takes as input a string-path and returns the image in a matrix or array form. Supported types of images are .png, .jpeg, .jpg, .tiff. 55 | #' Extension types similar to .tiff such as .tif, .TIFF, .TIF are also supported 56 | #' 57 | #' @importFrom png readPNG 58 | #' @importFrom jpeg readJPEG 59 | #' @importFrom tiff readTIFF 60 | #' 61 | #' @export 62 | #' @examples 63 | #' 64 | #' path = system.file("tmp_images", "1.png", package = "OpenImageR") 65 | #' 66 | #' image = readImage(path) 67 | #' 68 | 69 | 70 | readImage = function(path, ...) { 71 | 72 | try_err_file = inherits(tryCatch(normalizePath(path, mustWork = T), error = function(e) e), "error") 73 | if (!inherits(path, "character") || try_err_file == T) stop('the path to an image is invalid or the image does not exist!', call. = F) 74 | 75 | inp_img_ext = verify_image_extension(image_path = path) 76 | 77 | if (inp_img_ext %in% c("png", "PNG")) { 78 | img = png::readPNG(path, ...) 79 | } 80 | else if (inp_img_ext %in% c("jpg", "JPG", "jpeg", "JPEG")) { 81 | img = jpeg::readJPEG(path, ...) 82 | } 83 | else if (inp_img_ext %in% c("tiff", "tif", "TIFF", "TIF")) { 84 | img = tiff::readTIFF(path, ...) 85 | } 86 | else { 87 | stop('supported image types are .png, .jpeg, .jpg, .tif or .tiff (case insensitive)!', call. = F) 88 | } 89 | 90 | return(img) 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /R/shiny_rscript.R: -------------------------------------------------------------------------------- 1 | 2 | #' display an image 3 | #' 4 | #' 5 | #' This function displays an image 6 | #' 7 | #' @param file_path if file_path is a character string, then a shiny application is utilized. If file_path is a matrix, data.frame OR a 3-dimensional array (where the third dimension is equal to 3) then the grid.raster function of the base grid package is used. 8 | #' @param clear_viewer a boolean. If TRUE then the previous image will be removed in the viewer before displaying the next one 9 | #' @return displays an image 10 | #' @details 11 | #' This function displays an image using either a character path, a 2- or a 3-dimensional object where the third dimension is equal to 3 12 | #' 13 | #' @importFrom grid grid.raster 14 | #' 15 | #' @export 16 | #' @examples 17 | #' 18 | #' # path = system.file("tmp_images", "1.png", package = "OpenImageR") 19 | #' 20 | #' # imageShow(path) 21 | #' 22 | 23 | 24 | imageShow = function(file_path, clear_viewer = FALSE) { 25 | 26 | try_err_files = inherits(tryCatch(normalizePath(file_path, mustWork = T), error = function(e) e), "error") 27 | if (!inherits(file_path, "character") && length(dim(file_path)) == 2 && !is.matrix(file_path)) file_path = as.matrix(file_path) 28 | 29 | if (inherits(file_path, 'matrix') || inherits(file_path, 'array')) { 30 | 31 | file_path = func_chech_range(file_path) 32 | if (clear_viewer) grDevices::graphics.off() 33 | grid::grid.raster(file_path) 34 | } 35 | else if (inherits(file_path, "character") && try_err_files == F){ 36 | 37 | file_path <<- normalizePath(file_path) 38 | runUI() 39 | } 40 | else { 41 | stop('invalid path or object') 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /R/warp_affine.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | #' Get Affine Transform 4 | #' 5 | #' @param original_points a matrix object that corresponds to the original points 6 | #' @param transformed_points a matrix object that corresponds to the transformed points 7 | #' @return a matrix 8 | #' @references 9 | #' https://github.com/OlehOnyshchak/ImageTransformations/blob/master/AffineTransformation.ipynb 10 | #' @export 11 | #' @examples 12 | #' 13 | #' require(OpenImageR) 14 | #' 15 | #' r = 600 16 | #' c = 600 17 | #' offset = 50 18 | #' 19 | #' original_points = matrix(data = c(0, 0, r, 0, 0, c), 20 | #' nrow = 3, 21 | #' ncol = 2, 22 | #' byrow = TRUE) 23 | #' 24 | #' transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 25 | #' nrow = 3, 26 | #' ncol = 2, 27 | #' byrow = TRUE) 28 | #' 29 | #' M_aff = getAffineTransform(original_points = original_points, 30 | #' transformed_points = transformed_points) 31 | #' M_aff 32 | 33 | getAffineTransform = function(original_points, transformed_points) { 34 | return(get_affine_transform(original_points, transformed_points)) 35 | } 36 | 37 | 38 | #' Warp Affine 39 | #' 40 | #' @param img either a matrix or a 3-dimensional array (where the third dimension is equal to 3) with a range of values between 0 and 255 41 | #' @param M a matrix corresponding to the transformation matrix 42 | #' @param R a value corresponding to the destination number of rows 43 | #' @param C a value corresponding to the destination number of columns 44 | #' @param threads an integer specifying the number of threads to run in parallel. This parameter applies only if the input "img" parameter is of type matrix. 45 | #' @param verbose a boolean. If TRUE then information will be printed in the console 46 | #' @return either a matrix or a 3-dimensional array (where the third dimension is equal to 3) 47 | #' @references 48 | #' https://github.com/OlehOnyshchak/ImageTransformations/blob/master/AffineTransformation.ipynb 49 | #' @export 50 | #' @examples 51 | #' 52 | #' require(OpenImageR) 53 | #' 54 | #' path = system.file("tmp_images", "landscape.jpg", package = "OpenImageR") 55 | #' img = readImage(path) 56 | #' img = img * 255 57 | #' 58 | #' #............................. 59 | #' # compute the affine transform 60 | #' #............................. 61 | #' 62 | #' r = ncol(img) 63 | #' c = nrow(img) 64 | #' offset = 50 65 | #' 66 | #' original_points = matrix(data = c(0, 0, r, 0, 0, c), 67 | #' nrow = 3, 68 | #' ncol = 2, 69 | #' byrow = TRUE) 70 | #' 71 | #' transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 72 | #' nrow = 3, 73 | #' ncol = 2, 74 | #' byrow = TRUE) 75 | #' 76 | #' M_aff = getAffineTransform(original_points = original_points, 77 | #' transformed_points = transformed_points) 78 | #' 79 | #' #.............. 80 | #' # 2-dimensional 81 | #' #.............. 82 | #' 83 | #' img_2d = rgb_2gray(img) 84 | #' 85 | #' res_2d = warpAffine(img = img_2d, 86 | #' M = M_aff, 87 | #' R = r, 88 | #' C = c, 89 | #' threads = 1, 90 | #' verbose = TRUE) 91 | #' 92 | #' # imageShow(res_2d) 93 | #' 94 | #' #.............. 95 | #' # 3-dimensional 96 | #' #.............. 97 | #' 98 | #' res_3d = warpAffine(img = img, 99 | #' M = M_aff, 100 | #' R = r, 101 | #' C = c, 102 | #' verbose = TRUE) 103 | #' 104 | #' # imageShow(res_3d) 105 | #' 106 | 107 | warpAffine = function(img, M, R, C, threads = 1, verbose = FALSE) { 108 | 109 | if (verbose) t_start = Sys.time() 110 | if (!inherits(img, c('matrix', 'array'))) stop("The input 'img' parameter must be either a 'matrix' or '3-dimensional array' where the third dimension is equal to 3", call. = F) 111 | 112 | if (inherits(img, 'matrix')) { 113 | res_ = warpAffine_2d(img, M, R, C, threads) 114 | } 115 | else { 116 | if (dim(img)[3] != 3) stop("In case that the input parameter 'img' is of type array it has to be 3-dimensional where the third dimension is equal to 3", call. = F) 117 | res_ = warp_affine_3d(img, M, R, C) 118 | } 119 | 120 | if (verbose) { 121 | t_end = Sys.time() 122 | t = t_end - t_start 123 | cat(paste(c('time to complete :', round(t, digits = 4), attributes(t)$units), collapse = ' '), '\n') 124 | } 125 | 126 | return(res_) 127 | } 128 | 129 | -------------------------------------------------------------------------------- /R/write_image.R: -------------------------------------------------------------------------------- 1 | 2 | #' This function writes 2- or 3-dimensional image (where the third dimension is equal to 3) data to a file 3 | #' 4 | #' This function writes 2- or 3-dimensional image (where the third dimension is equal to 3) data to a file. Supported types are .png, .jpeg, .jpg, .tiff (or .tif, .TIFF, .TIF) 5 | #' 6 | #' @param data a 2- or 3-dimensional object (matrix, data frame or array where the third dimension is equal to 3) 7 | #' @param file_name a string specifying the name of the new file 8 | #' @param ... further arguments for the writePNG, writeJPEG and writeTIFF functions 9 | #' @return a saved image file 10 | #' @details 11 | #' This function takes as input a matrix, data frame or array and saves the data in one of the supported image types ( .png, .jpeg, .jpg, .tiff ). 12 | #' Extension types similar to .tiff such as .tif, .TIFF, .TIF are also supported 13 | #' 14 | #' @importFrom png writePNG 15 | #' @importFrom jpeg writeJPEG 16 | #' @importFrom tiff writeTIFF 17 | #' 18 | #' @export 19 | #' @examples 20 | #' 21 | #' # path = system.file("tmp_images", "1.png", package = "OpenImageR") 22 | #' 23 | #' # im = readImage(path) 24 | #' 25 | #' # writeImage(im, 'new_image.jpeg') 26 | #' 27 | 28 | 29 | writeImage = function(data, file_name, ...) { 30 | 31 | if (inherits(data, 'data.frame')) data = as.matrix(data) 32 | if (!inherits(data, c('matrix', 'array'))) stop('supported image data are matrix, data frame, array') 33 | if (!inherits(file_name, "character")) stop("The file_name should be a character string. For instance, '/home/my_image.png'") 34 | 35 | flag_type = strsplit(file_name, '[.]')[[1]] 36 | flag_type = flag_type[length(flag_type)] 37 | 38 | if (flag_type == "png") { 39 | 40 | png::writePNG(data, target = file_name, ...) 41 | } 42 | else if (flag_type == "jpg" || flag_type == "jpeg") { 43 | 44 | jpeg::writeJPEG(data, target = file_name, ...) 45 | } 46 | else if (flag_type %in% c("tiff", "tif", "TIFF", "TIF")) { 47 | 48 | tiff::writeTIFF(data, where = file_name, ...) 49 | } 50 | else { 51 | 52 | stop('supported image types are .png, .jpeg, .jpg, .tiff (or .tif, .TIFF, .TIF)') 53 | } 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![tic](https://github.com/mlampros/OpenImageR/workflows/tic/badge.svg?branch=master)](https://github.com/mlampros/OpenImageR/actions) 3 | [![codecov.io](https://codecov.io/github/mlampros/OpenImageR/coverage.svg?branch=master)](https://codecov.io/github/mlampros/OpenImageR?branch=master) 4 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/OpenImageR)](http://cran.r-project.org/package=OpenImageR) 5 | [![Downloads](http://cranlogs.r-pkg.org/badges/grand-total/OpenImageR?color=blue)](http://www.r-pkg.org/pkg/OpenImageR) 6 | Buy Me A Coffee 7 | [![](https://img.shields.io/docker/automated/mlampros/openimager.svg)](https://hub.docker.com/r/mlampros/openimager) 8 | [![Dependencies](https://tinyverse.netlify.com/badge/OpenImageR)](https://cran.r-project.org/package=OpenImageR) 9 | 10 | 11 | ## OpenImageR 12 |
13 | 14 | The OpenImageR package is an image processing library. It includes functions for image preprocessing, filtering and image recognition. More details on the functionality of OpenImageR can be found in the [first](http://mlampros.github.io/2016/07/08/OpenImageR/), [second](http://mlampros.github.io/2018/08/08/Gabor_Feature_Extraction/) and [third](http://mlampros.github.io/2018/11/09/Image_Segmentation_Superpixels_Clustering/) blog-posts, and in the package Documentation ( *scroll down for information on how to use the* **docker image** ) 15 |

16 | 17 | 18 | **UPDATE 06-11-2018** 19 | 20 | As of version 1.1.2 the *OpenImageR* package allows R package maintainers to perform **linking between packages at a C++ code (Rcpp) level**. This means that the Rcpp functions of the *OpenImageR* package can be called in the C++ files of another package. In the next lines I'll give detailed explanations on how this can be done: 21 | 22 |
23 | 24 | Assumming that an R package ('PackageA') calls one of the *OpenImageR* Rcpp functions. Then the maintainer of 'PackageA' has to : 25 | 26 |
27 | 28 | * **1st.** install the *OpenImageR* package to take advantage of the new functionality either from CRAN using, 29 | 30 |
31 | 32 | 33 | ```R 34 | 35 | install.packages("OpenImageR") 36 | 37 | 38 | ``` 39 | 40 |
41 | 42 | or download the latest version from Github using the *remotes* package, 43 | 44 |
45 | 46 | ```R 47 | 48 | remotes::install_github('mlampros/OpenImageR') 49 | 50 | 51 | ``` 52 | 53 |
54 | 55 | * **2nd.** update the **DESCRIPTION** file of 'PackageA' and especially the *LinkingTo* field by adding the *OpenImageR* package (besides any other packages), 56 | 57 |
58 | 59 | ```R 60 | 61 | LinkingTo: OpenImageR 62 | 63 | ``` 64 | 65 |
66 | 67 | * **3rd.** open a **new C++ file** (for instance in Rstudio) and at the top of the file add the following 'headers', 'depends' and 'plugins', 68 | 69 |
70 | 71 | ```R 72 | 73 | # include 74 | # include 75 | // [[Rcpp::depends("RcppArmadillo")]] 76 | // [[Rcpp::depends(OpenImageR)]] 77 | 78 | 79 | ``` 80 |
81 | 82 | The available C++ classes (*Utility_functions*, *Gabor_Features*, *Gabor_Features_Rcpp*, *HoG_features*, *Image_Hashing*) can be found in the **inst/include/OpenImageRheader.h** file. 83 | 84 |
85 | 86 | A *complete minimal example* would be : 87 | 88 |
89 | 90 | ```R 91 | 92 | # include 93 | # include 94 | // [[Rcpp::depends("RcppArmadillo")]] 95 | // [[Rcpp::depends(OpenImageR)]] 96 | 97 | 98 | // [[Rcpp::export]] 99 | arma::mat rgb_2gray_exp(arma::cube RGB_image) { 100 | 101 | oimageR::Utility_functions UTLF; 102 | return UTLF.rgb_2gray_rcpp(RGB_image); 103 | } 104 | 105 | 106 | ``` 107 | 108 |
109 | 110 | Then, by opening an R file a user can call the *rgb_2gray_exp* function using, 111 | 112 |
113 | 114 | ```R 115 | 116 | Rcpp::sourceCpp('example.cpp') # assuming that the previous Rcpp code is included in 'example.cpp' 117 | 118 | set.seed(1) 119 | im_rgb = array(runif(30000), c(100, 100, 3)) 120 | 121 | im_grey = rgb_2gray_exp(im_rgb) 122 | 123 | str(im_grey) 124 | 125 | ``` 126 | 127 |
128 | 129 | Use the following link to report bugs/issues, 130 |

131 | 132 | [https://github.com/mlampros/OpenImageR/issues](https://github.com/mlampros/OpenImageR/issues) 133 | 134 | 135 |
136 | 137 | 138 | **UPDATE 29-11-2019** 139 | 140 |
141 | 142 | **Docker images** of the *OpenImageR* package are available to download from my [dockerhub](https://hub.docker.com/r/mlampros/openimager) account. The images come with *Rstudio* and the *R-development* version (latest) installed. The whole process was tested on Ubuntu 18.04. To **pull** & **run** the image do the following, 143 | 144 |
145 | 146 | ```R 147 | 148 | docker pull mlampros/openimager:rstudiodev 149 | 150 | docker run -d --name rstudio_dev -e USER=rstudio -e PASSWORD=give_here_your_password --rm -p 8787:8787 mlampros/openimager:rstudiodev 151 | 152 | ``` 153 | 154 |
155 | 156 | The user can also **bind** a home directory / folder to the image to use its files by specifying the **-v** command, 157 | 158 |
159 | 160 | ```R 161 | 162 | docker run -d --name rstudio_dev -e USER=rstudio -e PASSWORD=give_here_your_password --rm -p 8787:8787 -v /home/YOUR_DIR:/home/rstudio/YOUR_DIR mlampros/openimager:rstudiodev 163 | 164 | 165 | ``` 166 | 167 |
168 | 169 | In the latter case you might have first give permission privileges for write access to **YOUR_DIR** directory (not necessarily) using, 170 | 171 |
172 | 173 | ```R 174 | 175 | chmod -R 777 /home/YOUR_DIR 176 | 177 | 178 | ``` 179 | 180 |
181 | 182 | The **USER** defaults to *rstudio* but you have to give your **PASSWORD** of preference (see [https://rocker-project.org/](https://rocker-project.org/) for more information). 183 | 184 |
185 | 186 | Open your web-browser and depending where the docker image was *build / run* give, 187 | 188 |
189 | 190 | **1st. Option** on your personal computer, 191 | 192 |
193 | 194 | ```R 195 | http://0.0.0.0:8787 196 | 197 | ``` 198 | 199 |
200 | 201 | **2nd. Option** on a cloud instance, 202 | 203 |
204 | 205 | ```R 206 | http://Public DNS:8787 207 | 208 | ``` 209 | 210 |
211 | 212 | to access the Rstudio console in order to give your username and password. 213 | 214 |
215 | 216 | ### **Citation:** 217 | 218 | If you use the code of this repository in your paper or research please cite both **OpenImageR** and the **original articles / software** `https://CRAN.R-project.org/package=OpenImageR`: 219 | 220 |
221 | 222 | ```R 223 | @Manual{, 224 | title = {{OpenImageR}: An Image Processing Toolkit}, 225 | author = {Lampros Mouselimis}, 226 | year = {2023}, 227 | note = {R package version 1.3.0}, 228 | url = {https://CRAN.R-project.org/package=OpenImageR}, 229 | } 230 | ``` 231 | 232 |
233 | 234 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("Please cite both the package and the original articles / software in your publications:") 2 | 3 | year <- sub("-.*", "", meta$Date) 4 | note <- sprintf("R package version %s", meta$Version) 5 | 6 | bibentry( 7 | bibtype = "Manual", 8 | title = "{OpenImageR}: An Image Processing Toolkit", 9 | author = person("Lampros", "Mouselimis"), 10 | year = year, 11 | note = note, 12 | url = "https://CRAN.R-project.org/package=OpenImageR" 13 | ) 14 | 15 | bibentry( 16 | bibtype = "Manual", 17 | title = "{SimpleCV}: The Open Source Framework for Machine Vision", 18 | author = person("Sight", "Machine"), 19 | year = "2012", 20 | note = "findHOGFeatures function of the SimpleCV computer vision platform", 21 | url = "https://github.com/sightmachine/SimpleCV" 22 | ) 23 | 24 | bibentry( 25 | bibtype = "Manual", 26 | title = "{imagehash}: A Python Perceptual Image Hashing Module", 27 | author = person("Johannes", "Buchner"), 28 | year = "2013", 29 | note = "average_hash, dhash and phash functions of the ImageHash python library", 30 | url = "https://github.com/JohannesBuchner/imagehash" 31 | ) 32 | 33 | bibentry( 34 | bibtype = "Article", 35 | title = "CloudID: Trustworthy cloud-based and cross-enterprise biometric identification", 36 | author = c(as.person("M. Haghighat"), as.person("S. Zonouz"), as.person("M. Abdel-Mottaleb")), 37 | journal = "Expert Systems with Applications", 38 | year = "2015", 39 | volume = "42", 40 | pages = "7905--7916", 41 | doi = "10.1016/j.eswa.2015.06.025" 42 | ) 43 | 44 | bibentry( 45 | bibtype = "Manual", 46 | title = "{gabor}: Gabor Feature Extraction", 47 | author = person("Mohammad", "Haghighat"), 48 | year = "2015", 49 | url = "https://github.com/mhaghighat/gabor" 50 | ) 51 | 52 | bibentry( 53 | bibtype = "Article", 54 | title = "SLIC Superpixels Compared to State-of-the-art Superpixel Methods", 55 | author = c(as.person("Radhakrishna Achanta"), as.person("Appu Shaji"), as.person("Kevin Smith"), as.person("Aurelien Lucchi"), as.person("Pascal Fua"), as.person("Sabine Suesstrunk")), 56 | journal = "IEEE Transactions on Pattern Analysis and Machine Intelligence", 57 | year = "2012", 58 | volume = "34", 59 | pages = "2274--2282", 60 | doi = "10.1109/TPAMI.2012.120" 61 | ) 62 | 63 | bibentry( 64 | bibtype = "TechReport", 65 | title = "SLIC Superpixels", 66 | author = c(as.person("Radhakrishna Achanta"), as.person("Appu Shaji"), as.person("Kevin Smith"), as.person("Aurelien Lucchi"), as.person("Pascal Fua"), as.person("Sabine Suesstrunk")), 67 | institution = "EPFL Technical Report", 68 | number = "149300", 69 | year = "2010" 70 | ) 71 | 72 | bibentry( 73 | bibtype = "Manual", 74 | title = "{ImageTransformations}: Implementation of OpenCV methods for affine and perspective transformation", 75 | author = person("Oleh", "Onyshchak"), 76 | year = "2019", 77 | url = "https://github.com/OlehOnyshchak" 78 | ) 79 | -------------------------------------------------------------------------------- /inst/COPYRIGHTS: -------------------------------------------------------------------------------- 1 | 2 | 3 | ==================================== 4 | 'SimpleCV' computer vision platform 5 | ==================================== 6 | 7 | 8 | I modified and extended the 'findHOGFeatures' function 9 | ---------------------------------------------------- 10 | 11 | 12 | Copyright (c) 2012, Sight Machine 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions are met: 17 | * Redistributions of source code must retain the above copyright 18 | notice, this list of conditions and the following disclaimer. 19 | * Redistributions in binary form must reproduce the above copyright 20 | notice, this list of conditions and the following disclaimer in the 21 | documentation and/or other materials provided with the distribution. 22 | * Neither the name of the nor the 23 | names of its contributors may be used to endorse or promote products 24 | derived from this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 27 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 30 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 33 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | 39 | 40 | =========================== 41 | 'ImageHash' python library 42 | =========================== 43 | 44 | 45 | I modified and extended the 'average_hash', 'dhash' and 'phash' functions 46 | -------------------------------------------------------------------- 47 | 48 | 49 | Copyright (c) 2013-2015, Johannes Buchner 50 | All rights reserved. 51 | 52 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 53 | 54 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 55 | 56 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 57 | 58 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 59 | 60 | 61 | 62 | #=============================================================== 63 | # Gabor Feature Extraction (based on Matlab code of the Author) 64 | #=============================================================== 65 | 66 | 67 | I modified and extended the 'Gabor Feature Extraction' functions 68 | #---------------------------------------------------------------- 69 | 70 | 71 | Copyright (c) 2015, Mohammad Haghighat All rights reserved. 72 | 73 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 74 | 75 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 76 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 77 | 78 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 79 | 80 | 81 | 82 | #========================================================== 83 | # WarpAffine function (based on Python code of the Author) 84 | #========================================================== 85 | 86 | MIT License 87 | 88 | Copyright (c) 2019 Oleh Onyshchak 89 | 90 | Permission is hereby granted, free of charge, to any person obtaining a copy 91 | of this software and associated documentation files (the "Software"), to deal 92 | in the Software without restriction, including without limitation the rights 93 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 94 | copies of the Software, and to permit persons to whom the Software is 95 | furnished to do so, subject to the following conditions: 96 | 97 | The above copyright notice and this permission notice shall be included in all 98 | copies or substantial portions of the Software. 99 | 100 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 101 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 102 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 103 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 104 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 105 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 106 | SOFTWARE. 107 | 108 | -------------------------------------------------------------------------------- /inst/documentation/AffineTransformation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/documentation/AffineTransformation.pdf -------------------------------------------------------------------------------- /inst/shiny_app/server.R: -------------------------------------------------------------------------------- 1 | 2 | function(input, output) { 3 | 4 | output$myImage <- shiny::renderImage({ 5 | 6 | list(src = file_path, 7 | 8 | height = input$height_width, 9 | 10 | width = input$height_width 11 | ) 12 | 13 | }, deleteFile = FALSE) 14 | } 15 | -------------------------------------------------------------------------------- /inst/shiny_app/ui.R: -------------------------------------------------------------------------------- 1 | 2 | shiny::pageWithSidebar( 3 | 4 | shiny::headerPanel("display image"), 5 | 6 | shiny::sidebarPanel( 7 | 8 | shiny::sliderInput("height_width", "Adjust Image Height and Width:", 9 | 10 | min = 1, max = 1000, value = 575) 11 | ), 12 | shiny::mainPanel( 13 | 14 | shiny::imageOutput("myImage") 15 | ) 16 | ) 17 | -------------------------------------------------------------------------------- /inst/tmp_images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/1.png -------------------------------------------------------------------------------- /inst/tmp_images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/2.jpg -------------------------------------------------------------------------------- /inst/tmp_images/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/3.jpeg -------------------------------------------------------------------------------- /inst/tmp_images/car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/car.png -------------------------------------------------------------------------------- /inst/tmp_images/landscape.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/landscape.jpg -------------------------------------------------------------------------------- /inst/tmp_images/same_type/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/same_type/1.png -------------------------------------------------------------------------------- /inst/tmp_images/same_type/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/same_type/10.png -------------------------------------------------------------------------------- /inst/tmp_images/same_type/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/same_type/4.png -------------------------------------------------------------------------------- /inst/tmp_images/same_type/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/same_type/5.png -------------------------------------------------------------------------------- /inst/tmp_images/same_type/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/same_type/8.png -------------------------------------------------------------------------------- /inst/tmp_images/slic_im.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/inst/tmp_images/slic_im.png -------------------------------------------------------------------------------- /man/Augmentation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{Augmentation} 4 | \alias{Augmentation} 5 | \title{image augmentations of a matrix, data frame, array or a list of 3-dimensional arrays (where the third dimension is equal to 3)} 6 | \usage{ 7 | Augmentation( 8 | image, 9 | flip_mode = NULL, 10 | crop_width = NULL, 11 | crop_height = NULL, 12 | resiz_width = 0, 13 | resiz_height = 0, 14 | resiz_method = "nearest", 15 | shift_rows = 0, 16 | shift_cols = 0, 17 | rotate_angle = 0, 18 | rotate_method = "nearest", 19 | zca_comps = 0, 20 | zca_epsilon = 0, 21 | image_thresh = 0, 22 | padded_value = 0, 23 | verbose = FALSE 24 | ) 25 | } 26 | \arguments{ 27 | \item{image}{a matrix, data frame, array or list of 3-dimensional arrays where the third dimension is equal to 3} 28 | 29 | \item{flip_mode}{a character string ('horizontal', 'vertical')} 30 | 31 | \item{crop_width}{an integer specifying the new width of the image, after the image is cropped. Corresponds to the image-rows.} 32 | 33 | \item{crop_height}{an integer specifying the new height of the image, after the image is cropped. Corresponds to the image-columns.} 34 | 35 | \item{resiz_width}{an integer specifying the new width of the image, after the image is resized. Corresponds to the image-rows.} 36 | 37 | \item{resiz_height}{an integer specifying the new height of the image, after the image is resized. Corresponds to the image-columns.} 38 | 39 | \item{resiz_method}{a string specifying the interpolation method when resizing an image ('nearest', 'bilinear')} 40 | 41 | \item{shift_rows}{a positive or negative integer specifying the direction that the rows should be shifted} 42 | 43 | \item{shift_cols}{a positive or negative integer specifying the direction that the columns should be shifted} 44 | 45 | \item{rotate_angle}{an integer specifying the rotation angle of the image} 46 | 47 | \item{rotate_method}{a string specifying the interpolation method when rotating an image ('nearest', 'bilinear')} 48 | 49 | \item{zca_comps}{an integer specifying the number of components to keep by zca whitening, when svd is performed} 50 | 51 | \item{zca_epsilon}{a float specifying the regularization parameter by zca whitening} 52 | 53 | \item{image_thresh}{the threshold parameter, by image thresholding, should be between 0 and 1 if the data is normalized or between 0-255 otherwise} 54 | 55 | \item{padded_value}{either a numeric value or a numeric vector of length equal to N of an N-dimensional array. If it's not equal to 0 then the values of the shifted rows or columns will be filled with the user-defined padded_value. Applies only to the shift_rows and shift_cols parameters.} 56 | 57 | \item{verbose}{a boolean (TRUE, FALSE). If TRUE, then the total time of the preprocessing task will be printed.} 58 | } 59 | \value{ 60 | the output is of the same type with the input (in case of a data frame it returns a matrix) 61 | } 62 | \description{ 63 | image augmentations of a matrix, data frame, array or a list of 3-dimensional arrays (where the third dimension is equal to 3) 64 | } 65 | \details{ 66 | This function takes advantage of various methods to accomplish image augmentations. The order of the preprocessing steps, in case that all transformations are applied to an image, 67 | is : 1st flip image, 2nd crop image, 3rd resize image, 4th shift rows or columns, 5th rotate image, 6th zca-whitening and 7th image-thresholding. 68 | } 69 | \examples{ 70 | 71 | \dontrun{ 72 | 73 | # a matrix 74 | object = matrix(1, 10, 10) 75 | 76 | res = Augmentation(object, resiz_width = 8, resiz_height = 8, rotate_angle = 40) 77 | 78 | 79 | # an array 80 | object = array(0, dim = c(10, 10, 3)) 81 | 82 | res = Augmentation(object, resiz_width = 8, resiz_height = 8, rotate_angle = 30) 83 | 84 | 85 | # an array (multiple matrices) 86 | object = array(0, dim = c(10, 10, 10)) 87 | 88 | res = Augmentation(object, resiz_width = 8, resiz_height = 8, rotate_angle = 20) 89 | 90 | 91 | # a list of 3-dimensional arrays (where the third dimension is equal to 3) 92 | object = list(array(0, dim = c(10, 10, 3)), array(0, dim = c(10, 10, 3))) 93 | 94 | res = Augmentation(object, resiz_width = 8, resiz_height = 8, rotate_angle = 40) 95 | } 96 | } 97 | \author{ 98 | Lampros Mouselimis 99 | } 100 | -------------------------------------------------------------------------------- /man/HOG.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hog_features_rscript.R 3 | \name{HOG} 4 | \alias{HOG} 5 | \title{calculate the HOG (Histogram of oriented gradients) for an image} 6 | \usage{ 7 | HOG(image, cells = 3, orientations = 6) 8 | } 9 | \arguments{ 10 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{cells}{the number of divisions ( cells )} 13 | 14 | \item{orientations}{number of orientation bins} 15 | } 16 | \value{ 17 | a numeric vector 18 | } 19 | \description{ 20 | The function is a modification of the 'findHOGFeatures' function of the SimpleCV package [ please consult the COPYRIGHT file ] 21 | The function takes either an RGB (it will be converted to gray) or a gray image and returns a vector of the HOG descriptors. 22 | The main purpose of the function is to create a vector of features, which can be used in classification tasks. 23 | } 24 | \details{ 25 | This function takes either a matrix, a data frame or a 3-dimensional array (where the third dimension is equal to 3) and returns a vector with the HOG-descriptors (histogram of oriented gradients). 26 | } 27 | \examples{ 28 | 29 | \dontrun{ 30 | 31 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 32 | 33 | image = readImage(path) 34 | 35 | res = HOG(image, cells = 3, orientations = 6) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /man/HOG_apply.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hog_features_rscript.R 3 | \name{HOG_apply} 4 | \alias{HOG_apply} 5 | \title{calculate the HOG (Histogram of oriented gradients) for a matrix, array or a folder of images} 6 | \usage{ 7 | HOG_apply( 8 | object, 9 | cells = 3, 10 | orientations = 6, 11 | rows = NULL, 12 | columns = NULL, 13 | threads = 1 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{a matrix, a data frame, a 3-dimensional array (where the third dimension is equal to 3) or a path to a folder of files (images)} 18 | 19 | \item{cells}{the number of divisions ( cells )} 20 | 21 | \item{orientations}{number of orientation bins} 22 | 23 | \item{rows}{a value specifying the number of rows of each image-row of the matrix (required if object is a matrix)} 24 | 25 | \item{columns}{a value specifying the number of columns of each image-row of the matrix (required if object is a matrix)} 26 | 27 | \item{threads}{the number of parallel cores to use} 28 | } 29 | \value{ 30 | If the input is a matrix, data frame or array it returns a matrix of the hog descriptors. If the input is a path to a folder it returns a list of length 2, 31 | the 1st sublist is a vector with the names of the image files (the order of the files in the vector corresponds to the order of the rows of the output matrix), 32 | the 2nd sublist is the matrix of the hog descriptors. 33 | } 34 | \description{ 35 | calculate the HOG (Histogram of oriented gradients) for a matrix, array or a folder of images 36 | } 37 | \details{ 38 | This function takes as input either a matrix, a data frame, a 3-dimensional array (where the third dimension is equal to 3) or a character path to a folder of files (images). It returns the HOG-descriptors 39 | (histogram of oriented gradients) for each row (if matrix or data frame), for each array-slice (if array) or for each file (if path to a folder of images). 40 | } 41 | \examples{ 42 | 43 | \dontrun{ 44 | 45 | MATR = matrix(runif(75), ncol = 25, nrow = 5) 46 | 47 | res = HOG_apply(MATR, cells = 3, orientations = 5, rows = 5, columns = 5, threads = 1) 48 | 49 | 50 | ARRAY = array(5, dim = c(10, 10, 3)) 51 | 52 | res = HOG_apply(ARRAY, cells = 3, orientations = 6, threads = 1) 53 | 54 | 55 | FOLDER_path = paste0(system.file("tmp_images", "same_type", package = "OpenImageR"), '/') 56 | 57 | res = HOG_apply(FOLDER_path, cells = 3, orientations = 6, threads = 1) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /man/List_2_Array.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{List_2_Array} 4 | \alias{List_2_Array} 5 | \title{convert a list of matrices to an array of matrices} 6 | \usage{ 7 | List_2_Array(data, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{a list of matrices} 11 | 12 | \item{verbose}{if TRUE then the time taken to complete the task will be printed} 13 | } 14 | \value{ 15 | an array 16 | } 17 | \description{ 18 | convert a list of matrices to an array of matrices 19 | } 20 | \details{ 21 | This is a helper function mainly for the HOG and hash functions. In case that matrices are stored in a list, 22 | this function converts the list to an array of 2-dimensional data. 23 | } 24 | \examples{ 25 | 26 | lst = list(matrix(0, 100, 100), matrix(1, 100, 100)) 27 | 28 | arr = List_2_Array(lst, verbose = FALSE) 29 | 30 | } 31 | \author{ 32 | Lampros Mouselimis 33 | } 34 | -------------------------------------------------------------------------------- /man/MinMaxObject.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{MinMaxObject} 4 | \alias{MinMaxObject} 5 | \title{minimum and maximum values of vector, matrix, data frame or array} 6 | \usage{ 7 | MinMaxObject(x) 8 | } 9 | \arguments{ 10 | \item{x}{either a vector, matrix, data frame or array} 11 | } 12 | \value{ 13 | a list 14 | } 15 | \description{ 16 | minimum and maximum values of vector, matrix, data frame or array 17 | } 18 | \details{ 19 | This helper function returns the minimum and maximum values of a vector, 2-dimensional or 3-dimensional objects (where the third dimension is equal to 3). In case of a vector, matrix or data frame it returns a single value for 20 | the minimum and maximum of the object. In case of an array it returns the minimum and maximum values for each slice of the array. 21 | } 22 | \examples{ 23 | 24 | # vector 25 | x = 1:10 26 | 27 | res = MinMaxObject(x) 28 | 29 | 30 | # matrix 31 | x = matrix(runif(100), 10, 10) 32 | 33 | res = MinMaxObject(x) 34 | 35 | 36 | # data frame 37 | x = data.frame(matrix(runif(100), 10, 10)) 38 | 39 | res = MinMaxObject(x) 40 | 41 | 42 | # array 43 | x = array(runif(300), dim = c(10, 10, 3)) 44 | 45 | res = MinMaxObject(x) 46 | 47 | } 48 | \author{ 49 | Lampros Mouselimis 50 | } 51 | -------------------------------------------------------------------------------- /man/NormalizeObject.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{NormalizeObject} 4 | \alias{NormalizeObject} 5 | \title{normalize a vector, matrix or array (in the range between 0 and 1)} 6 | \usage{ 7 | NormalizeObject(x) 8 | } 9 | \arguments{ 10 | \item{x}{either a vector, matrix, data frame or array} 11 | } 12 | \value{ 13 | either a normalized vector, matrix, or array 14 | } 15 | \description{ 16 | normalize a vector, matrix or array (in the range between 0 and 1) 17 | } 18 | \details{ 19 | This is a helper function which normalizes all pixel values of the object to the range between 0 and 1. The function takes either a vector, matrix, data frame or 20 | array as input and returns a normalized object of the same type (in case of data frame it returns a matrix). 21 | } 22 | \examples{ 23 | 24 | # vector 25 | x = 1:10 26 | 27 | res = NormalizeObject(x) 28 | 29 | 30 | # matrix 31 | x = matrix(runif(100), 10, 10) 32 | 33 | res = NormalizeObject(x) 34 | 35 | 36 | # data frame 37 | x = data.frame(matrix(runif(100), 10, 10)) 38 | 39 | res = NormalizeObject(x) 40 | 41 | 42 | # array 43 | x = array(runif(300), dim = c(10, 10, 3)) 44 | 45 | res = NormalizeObject(x) 46 | 47 | } 48 | \author{ 49 | Lampros Mouselimis 50 | } 51 | -------------------------------------------------------------------------------- /man/RGB_to_HSV.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{RGB_to_HSV} 4 | \alias{RGB_to_HSV} 5 | \title{Conversion of RGB to HSV colour type} 6 | \usage{ 7 | RGB_to_HSV(input_data) 8 | } 9 | \arguments{ 10 | \item{input_data}{a 3-dimensional array (RGB image) where the third dimension is equal to 3} 11 | } 12 | \description{ 13 | Conversion of RGB to HSV colour type 14 | } 15 | \details{ 16 | Meaning: RGB (Red-Green-Blue) to HSV (Hue, Saturation, Value) colour conversion 17 | } 18 | \examples{ 19 | 20 | library(OpenImageR) 21 | 22 | set.seed(1) 23 | array_3d = array(sample(1:255, 675, replace = TRUE), c(15, 15, 3)) 24 | 25 | res = RGB_to_HSV(array_3d) 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/RGB_to_Lab.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{RGB_to_Lab} 4 | \alias{RGB_to_Lab} 5 | \title{Conversion of RGB to Lab colour type} 6 | \usage{ 7 | RGB_to_Lab(input_data) 8 | } 9 | \arguments{ 10 | \item{input_data}{a 3-dimensional array (RGB image) where the third dimension is equal to 3} 11 | } 12 | \description{ 13 | Conversion of RGB to Lab colour type 14 | } 15 | \details{ 16 | Meaning: RGB (Red-Green-Blue) to LAB (Lightness, A-colour-dimension, B-colour-dimension) colour conversion 17 | } 18 | \examples{ 19 | 20 | library(OpenImageR) 21 | 22 | set.seed(1) 23 | array_3d = array(sample(1:255, 675, replace = TRUE), c(15, 15, 3)) 24 | 25 | res = RGB_to_Lab(array_3d) 26 | 27 | } 28 | \references{ 29 | https://www.epfl.ch/labs/ivrl/research/snic-superpixels/ 30 | } 31 | -------------------------------------------------------------------------------- /man/ZCAwhiten.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{ZCAwhiten} 4 | \alias{ZCAwhiten} 5 | \title{zca whiten of an image} 6 | \usage{ 7 | ZCAwhiten(image, k, epsilon) 8 | } 9 | \arguments{ 10 | \item{image}{a matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{k}{an integer specifying the number of components to keep when svd is performed (reduced dimension representation of the data)} 13 | 14 | \item{epsilon}{a float specifying the regularization parameter} 15 | } 16 | \value{ 17 | a matrix or 3-dimensional array where the third dimension is equal to 3 18 | } 19 | \description{ 20 | this function performs zca-whitening to a 2- or 3- dimensional image 21 | } 22 | \details{ 23 | Whitening (or sphering) is the preprocessing needed for some algorithms. If we are training on images, the raw input is redundant, since adjacent 24 | pixel values are highly correlated. When using whitening the features become less correlated and all features have the same variance. 25 | } 26 | \examples{ 27 | 28 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 29 | 30 | image = readImage(path) 31 | 32 | res = ZCAwhiten(image, k = 20, epsilon = 0.1) 33 | 34 | } 35 | \references{ 36 | http://ufldl.stanford.edu/wiki/index.php/Whitening 37 | } 38 | -------------------------------------------------------------------------------- /man/average_hash.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{average_hash} 4 | \alias{average_hash} 5 | \title{calculation of the 'average hash' of an image} 6 | \usage{ 7 | average_hash(gray_image, hash_size = 8, MODE = "hash", resize = "nearest") 8 | } 9 | \arguments{ 10 | \item{gray_image}{a (2-dimensional) matrix or data frame} 11 | 12 | \item{hash_size}{an integer specifying the hash size (should be less than number of rows or columns of the gray_image)} 13 | 14 | \item{MODE}{one of 'hash' (returns the hash of the image), 'binary' (returns binary identifier of the image)} 15 | 16 | \item{resize}{corresponds to one of 'nearest', 'bilinear' (resizing method)} 17 | } 18 | \value{ 19 | either a hash-string or a binary vector 20 | } 21 | \description{ 22 | This function calculates the average hash of an image 23 | } 24 | \details{ 25 | The function is a modification of the 'average_hash' function of the imagehash package [ please consult the COPYRIGHT file ]. The average hash works 26 | in the following way : 1st convert to grayscale, 2nd, reduce the size of an image (for instance to an 8x8 image, to further simplify 27 | the number of computations), 3rd average the resulting colors (for an 8x8 image we average 64 colors), 4th compute the bits by comparing if each color value 28 | is above or below the mean, 5th construct the hash. 29 | } 30 | \examples{ 31 | 32 | image = readImage(system.file("tmp_images", "1.png", package = "OpenImageR")) 33 | 34 | image = rgb_2gray(image) 35 | 36 | res_hash = average_hash(image, hash_size = 8, MODE = 'hash') 37 | 38 | res_binary = average_hash(image, hash_size = 8, MODE = 'binary') 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/convolution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{convolution} 4 | \alias{convolution} 5 | \title{convolution} 6 | \usage{ 7 | convolution(image, kernel, mode = "same") 8 | } 9 | \arguments{ 10 | \item{image}{either a matrix, data frame or array} 11 | 12 | \item{kernel}{a kernel in form of a matrix} 13 | 14 | \item{mode}{the convolution mode (one of 'same', 'full')} 15 | } 16 | \value{ 17 | either a matrix or an array, depending on the input data 18 | } 19 | \description{ 20 | convolution 21 | } 22 | \details{ 23 | This function performs convolution using a kernel matrix. When mode 'same' the output object has the same dimensions with the input, whereas 24 | when mode 'full' the rows and columns of the output object equals : ROWS = nrow(image) + nrow(kernel) - 1 and COLUMNS = ncol(image) + ncol(kernel) - 1 25 | } 26 | \examples{ 27 | 28 | 29 | # kernel 30 | x = matrix(1, nrow = 4, ncol = 4) / 16 # uniform 31 | 32 | 33 | # matrix 34 | image_matrix = matrix(runif(100), 10, 10) 35 | 36 | res = convolution(image_matrix, x, "same") 37 | 38 | 39 | # array 40 | image_array = array(runif(300), dim = c(10, 10, 3)) 41 | 42 | res = convolution(image_array, x, "same") 43 | 44 | } 45 | \author{ 46 | Lampros Mouselimis 47 | } 48 | -------------------------------------------------------------------------------- /man/cropImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{cropImage} 4 | \alias{cropImage} 5 | \title{crop an image} 6 | \usage{ 7 | cropImage(image, new_width, new_height, type = "equal_spaced") 8 | } 9 | \arguments{ 10 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{new_width}{Corresponds to the image-rows. If 'equal_spaced' then the new_width should be numeric of length 1. If 'user_defined' then the new_width should be a sequence of numeric values.} 13 | 14 | \item{new_height}{Corresponds to the image-columns. If 'equal_spaced' then the new_height should be numeric of length 1. If 'user_defined' then the new_height should be a sequence of numeric values.} 15 | 16 | \item{type}{a string specifying the type ('equal_spaced' or 'user_defined'). If 'equal_spaced' the image will be cropped towards the center (equal distances horizontaly and verticaly). If 'user_defined' the user specifies the cropped region.} 17 | } 18 | \value{ 19 | depending on the input, either a matrix or an array 20 | } 21 | \description{ 22 | crop an image 23 | } 24 | \details{ 25 | This function crops an image in two different ways. 26 | } 27 | \examples{ 28 | 29 | path = system.file("tmp_images", "2.jpg", package = "OpenImageR") 30 | 31 | image = readImage(path) 32 | 33 | # IF 'equal_spaced': 34 | crop1 = cropImage(image, new_width = 20, new_height = 20, type = 'equal_spaced') 35 | 36 | # IF 'user_defined': 37 | crop2 = cropImage(image, new_width = 5:20, new_height = 5:20, type = 'user_defined') 38 | 39 | } 40 | \author{ 41 | Lampros Mouselimis 42 | } 43 | -------------------------------------------------------------------------------- /man/crop_image_secondary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{crop_image_secondary} 4 | \alias{crop_image_secondary} 5 | \title{crop an image in R [ for RGB or grey images ]} 6 | \usage{ 7 | crop_image_secondary(image, new_width, new_height) 8 | } 9 | \description{ 10 | crop an image in R [ for RGB or grey images ] 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/delationErosion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{delationErosion} 4 | \alias{delationErosion} 5 | \title{Delation or Erosion of an image} 6 | \usage{ 7 | delationErosion(image, Filter, method = "delation", threads = 1) 8 | } 9 | \arguments{ 10 | \item{image}{a matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{Filter}{a vector specifying the dimensions of the kernel, which will be used to perform either delation or erosion, such as c(3,3)} 13 | 14 | \item{method}{one of 'delation', 'erosion'} 15 | 16 | \item{threads}{number of cores to run in parallel ( > 1 should be used if image high dimensional )} 17 | } 18 | \value{ 19 | a matrix or 3-dimensional array where the third dimension is equal to 3 20 | } 21 | \description{ 22 | `r lifecycle::badge("deprecated")` 23 | 24 | This function was deprecated because I realized that the name of the function does not correspond to the name of the algorithm (delation -> dilation) 25 | 26 | this function performs delation or erosion to a 2- or 3- dimensional image 27 | } 28 | \details{ 29 | This function utilizes a kernel to perform delation or erosion. The first value of the vector indicates the number of rows of the kernel, whereas 30 | the second value indicates the number of columns. 31 | } 32 | \examples{ 33 | 34 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 35 | 36 | image = readImage(path) 37 | 38 | res_delate = delationErosion(image, Filter = c(3,3), method = 'delation') 39 | 40 | res_erode = delationErosion(image, Filter = c(5,5), method = 'erosion') 41 | 42 | # -> 43 | 44 | res_dilate = dilationErosion(image, Filter = c(3,3), method = 'dilation') 45 | 46 | res_erode = dilationErosion(image, Filter = c(5,5), method = 'erosion') 47 | 48 | } 49 | \keyword{internal} 50 | -------------------------------------------------------------------------------- /man/dhash.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{dhash} 4 | \alias{dhash} 5 | \title{calculation of the 'dhash' of an image} 6 | \usage{ 7 | dhash(gray_image, hash_size = 8, MODE = "hash", resize = "nearest") 8 | } 9 | \arguments{ 10 | \item{gray_image}{a (2-dimensional) matrix or data frame} 11 | 12 | \item{hash_size}{an integer specifying the hash size (should be less than number of rows or columns of the gray_image)} 13 | 14 | \item{MODE}{one of 'hash' (returns the hash of the image), 'binary' (returns binary identifier of the image)} 15 | 16 | \item{resize}{corresponds to one of 'nearest', 'bilinear'} 17 | } 18 | \value{ 19 | either a hash-string or a binary vector 20 | } 21 | \description{ 22 | This function calculates the dhash of an image 23 | } 24 | \details{ 25 | The function is a modification of the 'dhash' function of the imagehash package [ please consult the COPYRIGHT file ]. In comparison to 26 | average_hash and phash, the dhash algorithm takes into consideration the difference between adjacent pixels. 27 | } 28 | \examples{ 29 | 30 | image = readImage(system.file("tmp_images", "3.jpeg", package = "OpenImageR")) 31 | 32 | image = rgb_2gray(image) 33 | 34 | res_hash = dhash(image, hash_size = 8, MODE = 'hash') 35 | 36 | res_binary = dhash(image, hash_size = 8, MODE = 'binary') 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/dilationErosion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{dilationErosion} 4 | \alias{dilationErosion} 5 | \title{Dilation or Erosion of an image} 6 | \usage{ 7 | dilationErosion(image, Filter, method = "dilation", threads = 1) 8 | } 9 | \arguments{ 10 | \item{image}{a matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{Filter}{a vector specifying the dimensions of the kernel, which will be used to perform either dilation or erosion, such as c(3,3)} 13 | 14 | \item{method}{one of 'dilation', 'erosion'} 15 | 16 | \item{threads}{number of cores to run in parallel ( > 1 should be used if image high dimensional )} 17 | } 18 | \value{ 19 | a matrix or 3-dimensional array where the third dimension is equal to 3 20 | } 21 | \description{ 22 | this function performs dilation or erosion to a 2- or 3- dimensional image 23 | } 24 | \details{ 25 | This function utilizes a kernel to perform dilation or erosion. The first value of the vector indicates the number of rows of the kernel, whereas 26 | the second value indicates the number of columns. 27 | } 28 | \examples{ 29 | 30 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 31 | 32 | image = readImage(path) 33 | 34 | res_dilate = dilationErosion(image, Filter = c(3,3), method = 'dilation') 35 | 36 | res_erode = dilationErosion(image, Filter = c(5,5), method = 'erosion') 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/down_sample_image.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{down_sample_image} 4 | \alias{down_sample_image} 5 | \title{downsampling an image ( by a factor ) using gaussian blur} 6 | \usage{ 7 | down_sample_image( 8 | image, 9 | factor, 10 | gaussian_blur = FALSE, 11 | gauss_sigma = 1, 12 | range_gauss = 2 13 | ) 14 | } 15 | \arguments{ 16 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 17 | 18 | \item{factor}{a positive number greater or equal to 1.0} 19 | 20 | \item{gaussian_blur}{a boolean (TRUE,FALSE) specifying if gaussian blur should be applied when downsampling} 21 | 22 | \item{gauss_sigma}{float parameter sigma for the gaussian filter} 23 | 24 | \item{range_gauss}{float number specifying the range of values for the gaussian filter} 25 | } 26 | \value{ 27 | depending on the input, either a matrix or an array 28 | } 29 | \description{ 30 | downsampling an image ( by a factor ) using gaussian blur 31 | } 32 | \details{ 33 | This function downsamples an image with the option to use gaussian blur for optimal output. 34 | } 35 | \examples{ 36 | 37 | path = system.file("tmp_images", "2.jpg", package = "OpenImageR") 38 | 39 | image = readImage(path) 40 | 41 | dsamp = down_sample_image(image, factor = 2.0, gaussian_blur = TRUE) 42 | 43 | } 44 | \author{ 45 | Lampros Mouselimis 46 | } 47 | -------------------------------------------------------------------------------- /man/edge_detection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{edge_detection} 4 | \alias{edge_detection} 5 | \title{edge detection (Frei_chen, LoG, Prewitt, Roberts_cross, Scharr, Sobel)} 6 | \usage{ 7 | edge_detection( 8 | image, 9 | method = NULL, 10 | conv_mode = "same", 11 | approx = F, 12 | gaussian_dims = 5, 13 | sigma = 1, 14 | range_gauss = 2, 15 | laplacian_type = 1 16 | ) 17 | } 18 | \arguments{ 19 | \item{image}{matrix or 3-dimensional array and the third dimension must be equal to 3} 20 | 21 | \item{method}{the method should be one of 'Frei_chen', 'LoG' (Laplacian of Gaussian), 'Prewitt', 'Roberts_cross', 'Scharr', 'Sobel'} 22 | 23 | \item{conv_mode}{the convolution mode should be one of 'same', 'full'} 24 | 25 | \item{approx}{if TRUE, approximate calculation of gradient (applies to all filters except for 'LoG')} 26 | 27 | \item{gaussian_dims}{integer specifying the horizontal and vertical dimensions of the gaussian filter} 28 | 29 | \item{sigma}{float parameter sigma for the gaussian filter} 30 | 31 | \item{range_gauss}{float number specifying the range of values for the gaussian filter} 32 | 33 | \item{laplacian_type}{integer value specifying the type for the laplacian kernel (one of 1, 2, 3, 4)} 34 | } 35 | \value{ 36 | depending on the input, either a matrix or an array 37 | } 38 | \description{ 39 | edge detection (Frei_chen, LoG, Prewitt, Roberts_cross, Scharr, Sobel) 40 | } 41 | \details{ 42 | This function takes either a matrix or a 3-dimensional array (where the third dimension is equal to 3) and it performs edge detection using one of the following filters : 'Frei_chen', 'LoG' (Laplacian of Gaussian), 43 | 'Prewitt', 'Roberts_cross', 'Scharr', 'Sobel' 44 | } 45 | \examples{ 46 | 47 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 48 | 49 | image = readImage(path) 50 | 51 | res = edge_detection(image, method = 'Frei_chen', conv_mode = 'same') 52 | 53 | } 54 | \author{ 55 | Lampros Mouselimis 56 | } 57 | -------------------------------------------------------------------------------- /man/flipImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{flipImage} 4 | \alias{flipImage} 5 | \title{flip image horizontally or vertically} 6 | \usage{ 7 | flipImage(image, mode = "horizontal") 8 | } 9 | \arguments{ 10 | \item{image}{a matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{mode}{one of 'horizontal', 'vertical'} 13 | } 14 | \value{ 15 | a matrix or 3-dimensional array where the third dimension is equal to 3 16 | } 17 | \description{ 18 | flip an image row-wise (horizontally) or column-wise (vertically) 19 | } 20 | \details{ 21 | This function flips an image row-wise or column-wise 22 | } 23 | \examples{ 24 | 25 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 26 | 27 | im = readImage(path) 28 | 29 | flp = flipImage(im, mode = 'vertical') 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/func_chech_range.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{func_chech_range} 4 | \alias{func_chech_range} 5 | \title{function to check the range of values of an image or normalize an image} 6 | \usage{ 7 | func_chech_range(image) 8 | } 9 | \description{ 10 | function to check the range of values of an image or normalize an image 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/func_transform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hog_features_rscript.R 3 | \name{func_transform} 4 | \alias{func_transform} 5 | \title{secondary function for HOG_apply} 6 | \usage{ 7 | func_transform(image, folder_path, flag_type, RGB_2gray = F) 8 | } 9 | \description{ 10 | secondary function for HOG_apply 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/gamma_correction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{gamma_correction} 4 | \alias{gamma_correction} 5 | \title{Gamma correction} 6 | \usage{ 7 | gamma_correction(image, gamma) 8 | } 9 | \arguments{ 10 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{gamma}{a positive value} 13 | } 14 | \value{ 15 | depending on the input, either a matrix or an array 16 | } 17 | \description{ 18 | Gamma correction 19 | } 20 | \details{ 21 | This function applies gamma correction to a matrix or to a 3-dimensional array where the third dimension is equal to 3. The gamma correction controls the overall brightness of an image. 22 | } 23 | \examples{ 24 | 25 | path = system.file("tmp_images", "2.jpg", package = "OpenImageR") 26 | 27 | image = readImage(path) 28 | 29 | filt = gamma_correction(image, gamma = 0.5) 30 | 31 | } 32 | \author{ 33 | Lampros Mouselimis 34 | } 35 | -------------------------------------------------------------------------------- /man/gaussian_kernel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{gaussian_kernel} 4 | \alias{gaussian_kernel} 5 | \title{gaussian-kernel} 6 | \usage{ 7 | gaussian_kernel(xy_length = 2, sigma = 1, range_gauss = 2) 8 | } 9 | \description{ 10 | gaussian-kernel 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/getAffineTransform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/warp_affine.R 3 | \name{getAffineTransform} 4 | \alias{getAffineTransform} 5 | \title{Get Affine Transform} 6 | \usage{ 7 | getAffineTransform(original_points, transformed_points) 8 | } 9 | \arguments{ 10 | \item{original_points}{a matrix object that corresponds to the original points} 11 | 12 | \item{transformed_points}{a matrix object that corresponds to the transformed points} 13 | } 14 | \value{ 15 | a matrix 16 | } 17 | \description{ 18 | Get Affine Transform 19 | } 20 | \examples{ 21 | 22 | require(OpenImageR) 23 | 24 | r = 600 25 | c = 600 26 | offset = 50 27 | 28 | original_points = matrix(data = c(0, 0, r, 0, 0, c), 29 | nrow = 3, 30 | ncol = 2, 31 | byrow = TRUE) 32 | 33 | transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 34 | nrow = 3, 35 | ncol = 2, 36 | byrow = TRUE) 37 | 38 | M_aff = getAffineTransform(original_points = original_points, 39 | transformed_points = transformed_points) 40 | M_aff 41 | } 42 | \references{ 43 | https://github.com/OlehOnyshchak/ImageTransformations/blob/master/AffineTransformation.ipynb 44 | } 45 | -------------------------------------------------------------------------------- /man/hash_apply.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{hash_apply} 4 | \alias{hash_apply} 5 | \title{calculate the binary or the hexadecimal hash for a matrix, array or a folder of images for the average_hash, phash or dhash functions} 6 | \usage{ 7 | hash_apply( 8 | object, 9 | rows = 28, 10 | columns = 28, 11 | hash_size = 8, 12 | highfreq_factor = 3, 13 | method = "phash", 14 | mode = "binary", 15 | threads = 1, 16 | resize = "nearest" 17 | ) 18 | } 19 | \arguments{ 20 | \item{object}{a matrix, a data frame, a 3-dimensional array (where the third dimension is equal to 3) or a path to a folder of files (images)} 21 | 22 | \item{rows}{a number specifying the number of rows of the matrix} 23 | 24 | \item{columns}{a number specifying the number of columns of the matrix} 25 | 26 | \item{hash_size}{an integer specifying the hash size. IF method = 'phash' : the hash_size * highfreq_factor should be less than number of rows or columns of the gray_image. 27 | IF method = 'dhash' or 'average_hash' : the hash_size should be less than number of rows or columns of the gray_image} 28 | 29 | \item{highfreq_factor}{an integer specyfing the highfrequency factor (IF method = 'phash' : the hash_size * highfreq_factor should be less than number of rows or columns of the gray_image)} 30 | 31 | \item{method}{one of 'phash', 'average_hash', 'dhash'} 32 | 33 | \item{mode}{one of 'binary', 'hash'} 34 | 35 | \item{threads}{the number of cores to run in parallel} 36 | 37 | \item{resize}{corresponds to one of 'nearest', 'bilinear' (resizing method)} 38 | } 39 | \value{ 40 | If the input is a matrix, data frame or array this function returns a matrix (if mode = 'binary') or a character vector (if mode = 'hex_hash'). If the input is a path to 41 | a folder the function returns a list of length 2, the 1st sublist is a vector with the names of the image files (the order of the files in the vector corresponds to the order of 42 | the rows of the output matrix), the 2nd sublist is a matrix (if mode = 'binary') or a character vector (if mode = 'hex_hash'). 43 | } 44 | \description{ 45 | This function takes either a matrix, array or a folder and returns either the binary hash features or the hashes (as a character vector) 46 | } 47 | \details{ 48 | This function calculates the binary hash or the hexadecimal hash for various types of objects. 49 | } 50 | \examples{ 51 | 52 | path = paste0(system.file("tmp_images", "same_type", package = "OpenImageR"), '/') 53 | 54 | res_phash = hash_apply(path, method = 'phash', mode = 'binary') 55 | 56 | } 57 | -------------------------------------------------------------------------------- /man/imageShow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/shiny_rscript.R 3 | \name{imageShow} 4 | \alias{imageShow} 5 | \title{display an image} 6 | \usage{ 7 | imageShow(file_path, clear_viewer = FALSE) 8 | } 9 | \arguments{ 10 | \item{file_path}{if file_path is a character string, then a shiny application is utilized. If file_path is a matrix, data.frame OR a 3-dimensional array (where the third dimension is equal to 3) then the grid.raster function of the base grid package is used.} 11 | 12 | \item{clear_viewer}{a boolean. If TRUE then the previous image will be removed in the viewer before displaying the next one} 13 | } 14 | \value{ 15 | displays an image 16 | } 17 | \description{ 18 | This function displays an image 19 | } 20 | \details{ 21 | This function displays an image using either a character path, a 2- or a 3-dimensional object where the third dimension is equal to 3 22 | } 23 | \examples{ 24 | 25 | # path = system.file("tmp_images", "1.png", package = "OpenImageR") 26 | 27 | # imageShow(path) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/image_thresholding.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{image_thresholding} 4 | \alias{image_thresholding} 5 | \title{image thresholding} 6 | \usage{ 7 | image_thresholding(image, thresh) 8 | } 9 | \arguments{ 10 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{thresh}{the threshold parameter should be between 0 and 1 if the data is normalized or between 0-255 otherwise} 13 | } 14 | \value{ 15 | a matrix 16 | } 17 | \description{ 18 | image thresholding 19 | } 20 | \details{ 21 | This function applies thresholding to a matrix or to a 3-dimensional array where the third dimension is equal to 3. 22 | } 23 | \examples{ 24 | 25 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 26 | 27 | image = readImage(path) 28 | 29 | filt = image_thresholding(image, thresh = 0.5) 30 | 31 | } 32 | \author{ 33 | Lampros Mouselimis 34 | } 35 | -------------------------------------------------------------------------------- /man/invariant_hash.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{invariant_hash} 4 | \alias{invariant_hash} 5 | \title{invariant hashing (caclulation of the hamming or the levenshtein distance when the image is flipped, rotated or cropped)} 6 | \usage{ 7 | invariant_hash( 8 | image, 9 | new_image, 10 | method = "phash", 11 | mode = "binary", 12 | hash_size = 8, 13 | highfreq_factor = 4, 14 | resize = "nearest", 15 | flip = T, 16 | rotate = T, 17 | angle_bidirectional = 10, 18 | crop = T 19 | ) 20 | } 21 | \arguments{ 22 | \item{image}{a 2-dimensional matrix or data frame (only gray-scale images are valid)} 23 | 24 | \item{new_image}{a new image to be compared with the previous input image} 25 | 26 | \item{method}{one of 'phash', 'average_hash', 'dhash'} 27 | 28 | \item{mode}{one of 'binary', 'hash'} 29 | 30 | \item{hash_size}{an integer specifying the hash size. IF method = 'phash' : the hash_size * highfreq_factor should be less than number of floor(rows * 0.8) or floor(columns * 0.8) of the gray_image 31 | IF method = 'dhash' or 'average_hash' : the hash_size should be less than number of floor(rows * 0.8) or floor(columns * 0.8) of the gray_image} 32 | 33 | \item{highfreq_factor}{an integer specyfing the highfrequency factor (IF method = 'phash' : the hash_size * highfreq_factor should be less than number of floor(rows * 0.8) or 34 | floor(columns * 0.8) of the gray_image)} 35 | 36 | \item{resize}{corresponds to one of 'nearest', 'bilinear' (resizing method)} 37 | 38 | \item{flip}{if TRUE the new_image will be flipped both horizontal and vertical} 39 | 40 | \item{rotate}{if TRUE the new_image will be rotated for a specified angle (see angle_bidirectional)} 41 | 42 | \item{angle_bidirectional}{a float specifying the angle that the images should be rotated in both directions. For instance, if angle_bidirectional = 10 then the image will be rotated for 10 and 43 | 350 (360-10) degrees.} 44 | 45 | \item{crop}{if TRUE the new_image will be cropped 10 or 20 percent (equally spaced horizontally and vertically)} 46 | } 47 | \value{ 48 | If flip, rotate and crop are all FALSE then the function returns either the hamming distance (if mode = 'binary') or the levenshtein distance (if mode = 'hash') for the two images. 49 | If any of the flip, rotate, crop is TRUE then it returns the MIN, MAX of the hamming distance (if mode = 'binary') or the MIN,MAX of the levenshtein distance (if mode = 'hash'). 50 | } 51 | \description{ 52 | flip-rotate-crop an image and caclulate the hamming or the levenshtein distance for phash, average_hash, dhash 53 | } 54 | \details{ 55 | This function performs the following transformations : flips an image (no-flip, horizonal-flip, vertical-flip), rotates an image (no-angle, angle_bidirectional, 360-angle_bidirectional) and 56 | crops an image (no-crop, 10-percent-crop, 20-percent-crop). Depending on the type of mode ('binary', 'hash'), after each transformation the hamming or the levenshtein distance between the two images is calculated. 57 | } 58 | \examples{ 59 | 60 | \dontrun{ 61 | 62 | path1 = system.file("tmp_images", "1.png", package = "OpenImageR") 63 | 64 | path2 = system.file("tmp_images", "2.jpg", package = "OpenImageR") 65 | 66 | image1 = rgb_2gray(readImage(path1)) 67 | 68 | image2 = rgb_2gray(readImage(path2)) 69 | 70 | res1 = invariant_hash(image1, image2, hash_size = 3, flip = TRUE, crop = FALSE) 71 | 72 | res2 = invariant_hash(image1, image2, mode = 'hash', hash_size = 3, angle_bidirectional = 10) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /man/laplacian_kernels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{laplacian_kernels} 4 | \alias{laplacian_kernels} 5 | \title{laplacian kernels} 6 | \usage{ 7 | laplacian_kernels(type = 1) 8 | } 9 | \description{ 10 | laplacian kernels 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/load_binary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{load_binary} 4 | \alias{load_binary} 5 | \title{loads either 2- or 3-dimensional data (where the third dimension is equal to 3) from a binary file} 6 | \usage{ 7 | load_binary(path, type) 8 | } 9 | \arguments{ 10 | \item{path}{a character string specifying a file path ( where the binary data is saved )} 11 | 12 | \item{type}{a character string. Either '2d' or '3d' to indicate what kind of data data will be loaded from the specified \emph{path}} 13 | } 14 | \description{ 15 | loads either 2- or 3-dimensional data (where the third dimension is equal to 3) from a binary file 16 | } 17 | \details{ 18 | This function can be used to load either 2- or 3-dimensional data (where the third dimension is equal to 3) from a binary file. It is used in combination with the \emph{superpixels} function in case that the \emph{write_slic} parameter is not an empty string (""). 19 | } 20 | \examples{ 21 | 22 | \dontrun{ 23 | 24 | library(OpenImageR) 25 | 26 | #------------------------------------------ 27 | # assuming the saved data are 2-dimensional 28 | #------------------------------------------ 29 | 30 | path = "/my_dir/data.bin" 31 | 32 | res = load_binary(path, type = '2d') 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/norm_matrix_range.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{norm_matrix_range} 4 | \alias{norm_matrix_range} 5 | \title{Normalize a matrix to specific range of values} 6 | \usage{ 7 | norm_matrix_range(data, min_value = -1, max_value = 1) 8 | } 9 | \arguments{ 10 | \item{data}{a matrix} 11 | 12 | \item{min_value}{the new minimum value for the input \emph{data}} 13 | 14 | \item{max_value}{the new maximum value for the input \emph{data}} 15 | } 16 | \value{ 17 | a matrix 18 | } 19 | \description{ 20 | Normalize a matrix to specific range of values 21 | } 22 | \examples{ 23 | 24 | set.seed(1) 25 | mt = matrix(1:48, 8, 6) 26 | 27 | res = norm_matrix_range(mt, min_value = -1, max_value = 1) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/padding.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{padding} 4 | \alias{padding} 5 | \title{Padding of matrices or n-dimensional arrays with a user specified value} 6 | \usage{ 7 | padding(input_data, new_rows, new_cols, fill_value = 0) 8 | } 9 | \arguments{ 10 | \item{input_data}{either a matrix or a 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{new_rows}{an integer specifying the new rows of the output matrix or array} 13 | 14 | \item{new_cols}{an integer specifying the new columns of the output matrix or array} 15 | 16 | \item{fill_value}{a numeric value to fill the extended rows / columns of the initial input data} 17 | } 18 | \value{ 19 | a list 20 | } 21 | \description{ 22 | Padding of matrices or n-dimensional arrays with a user specified value 23 | } 24 | \details{ 25 | The \emph{padding} function returns a list, where \emph{data} is the padded / extended matrix or array and \emph{padded_start}, \emph{padded_end}, \emph{padded_left} and \emph{padded_right} are integer values specifying how 26 | many rows or columsn in up-, down-, left- or right-direction the input matrix or array was padded / extended with the specified fill-value. 27 | } 28 | \examples{ 29 | 30 | library(OpenImageR) 31 | 32 | 33 | #------- 34 | # matrix 35 | #------- 36 | 37 | set.seed(1) 38 | mt = matrix(runif(100), 10, 10) 39 | 40 | res_mt = padding(mt, 15, 20, fill_value = -1) 41 | 42 | 43 | #------ 44 | # array 45 | #------ 46 | 47 | lst = list(matrix(1, 10, 10), matrix(2, 10, 10)) 48 | 49 | arr = List_2_Array(lst, verbose = FALSE) 50 | 51 | res_arr = padding(arr, 15, 20, fill_value = mean(as.vector(mt))) 52 | 53 | } 54 | -------------------------------------------------------------------------------- /man/phash.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{phash} 4 | \alias{phash} 5 | \title{calculation of the 'phash' of an image} 6 | \usage{ 7 | phash( 8 | gray_image, 9 | hash_size = 8, 10 | highfreq_factor = 4, 11 | MODE = "hash", 12 | resize = "nearest" 13 | ) 14 | } 15 | \arguments{ 16 | \item{gray_image}{a (2-dimensional) matrix or data frame} 17 | 18 | \item{hash_size}{an integer specifying the hash size (hash_size * highfreq_factor should be less than number of rows or columns of the gray_image)} 19 | 20 | \item{highfreq_factor}{an integer specyfing the highfrequency factor (hash_size * highfreq_factor should be less than number of rows or columns of the gray_image)} 21 | 22 | \item{MODE}{one of 'hash' (returns the hash of the image), 'binary' (returns binary identifier of the image)} 23 | 24 | \item{resize}{corresponds to one of 'nearest', 'bilinear' (resizing method)} 25 | } 26 | \value{ 27 | either a hash-string or a binary vector 28 | } 29 | \description{ 30 | This function calculates the phash of an image 31 | } 32 | \details{ 33 | The function is a modification of the 'phash' function of the imagehash package [ please consult the COPYRIGHT file ]. The phash algorithm 34 | extends the average_hash by using the discrete cosine transform. 35 | } 36 | \examples{ 37 | 38 | image = readImage(system.file("tmp_images", "2.jpg", package = "OpenImageR")) 39 | 40 | image = rgb_2gray(image) 41 | 42 | res_hash = phash(image, hash_size = 6, highfreq_factor = 3, MODE = 'hash') 43 | 44 | res_binary = phash(image, hash_size = 6, highfreq_factor = 3, MODE = 'binary') 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/readImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_image.R 3 | \name{readImage} 4 | \alias{readImage} 5 | \title{this function reads various types of images} 6 | \usage{ 7 | readImage(path, ...) 8 | } 9 | \arguments{ 10 | \item{path}{a character string specifying the path to the saved image} 11 | 12 | \item{...}{further arguments for the readPNG, readJPEG and readTIFF functions} 13 | } 14 | \value{ 15 | the image in a matrix or array form 16 | } 17 | \description{ 18 | Reads images of type .png, .jpeg, .jpg, .tiff 19 | } 20 | \details{ 21 | This function takes as input a string-path and returns the image in a matrix or array form. Supported types of images are .png, .jpeg, .jpg, .tiff. 22 | Extension types similar to .tiff such as .tif, .TIFF, .TIF are also supported 23 | } 24 | \examples{ 25 | 26 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 27 | 28 | image = readImage(path) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/resizeImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{resizeImage} 4 | \alias{resizeImage} 5 | \title{resize an image using the 'nearest neighbors' or the 'bilinear' method} 6 | \usage{ 7 | resizeImage(image, width, height, method = "nearest", normalize_pixels = FALSE) 8 | } 9 | \arguments{ 10 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{width}{a number specifying the new width of the image. Corresponds to the image-rows.} 13 | 14 | \item{height}{a number specifying the new height of the image. Corresponds to the image-columns.} 15 | 16 | \item{method}{one of 'nearest', 'bilinear'} 17 | 18 | \item{normalize_pixels}{a boolean. If TRUE, then the output pixel values will be divided by 255.0} 19 | } 20 | \value{ 21 | depending on the input, either a matrix or an array 22 | } 23 | \description{ 24 | resize an image using the 'nearest neighbors' or the 'bilinear' method 25 | } 26 | \details{ 27 | This function down- or upsamples an image using the 'nearest neighbors' or the 'bilinear' method 28 | } 29 | \examples{ 30 | 31 | path = system.file("tmp_images", "2.jpg", package = "OpenImageR") 32 | 33 | image = readImage(path) 34 | 35 | resiz = resizeImage(image, width = 32, height = 32, method = 'nearest') 36 | 37 | } 38 | \author{ 39 | Lampros Mouselimis 40 | } 41 | -------------------------------------------------------------------------------- /man/rgb_2gray.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{rgb_2gray} 4 | \alias{rgb_2gray} 5 | \title{convert an RGB image to Gray} 6 | \usage{ 7 | rgb_2gray(RGB_image) 8 | } 9 | \arguments{ 10 | \item{RGB_image}{a 3-dimensional array where the third dimension is equal to 3} 11 | } 12 | \value{ 13 | a matrix 14 | } 15 | \description{ 16 | convert an RGB image to Gray 17 | } 18 | \details{ 19 | This function converts an RGB image to gray 20 | } 21 | \examples{ 22 | 23 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 24 | 25 | image = readImage(path) 26 | 27 | gray = rgb_2gray(image) 28 | 29 | } 30 | \author{ 31 | Lampros Mouselimis 32 | } 33 | -------------------------------------------------------------------------------- /man/rotateFixed.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{rotateFixed} 4 | \alias{rotateFixed} 5 | \title{Rotate an image by 90, 180, 270 degrees} 6 | \usage{ 7 | rotateFixed(image, angle) 8 | } 9 | \arguments{ 10 | \item{image}{matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{angle}{one of 90, 180 and 270 degrees} 13 | } 14 | \value{ 15 | depending on the input, either a matrix or an array 16 | } 17 | \description{ 18 | Rotate an image by 90, 180, 270 degrees 19 | } 20 | \details{ 21 | This function is faster than the rotateImage function as it rotates an image for specific angles (90, 180 or 270 degrees). 22 | } 23 | \examples{ 24 | 25 | path = system.file("tmp_images", "3.jpeg", package = "OpenImageR") 26 | 27 | image = readImage(path) 28 | 29 | r = rotateFixed(image, 90) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/rotateImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{rotateImage} 4 | \alias{rotateImage} 5 | \title{Rotate an image using the 'nearest' or 'bilinear' method} 6 | \usage{ 7 | rotateImage(image, angle, method = "nearest", mode = "same", threads = 1) 8 | } 9 | \arguments{ 10 | \item{image}{matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{angle}{specifies the number of degrees} 13 | 14 | \item{method}{a string specifying the interpolation method when rotating an image ( 'nearest', 'bilinear' )} 15 | 16 | \item{mode}{one of 'full', 'same' (same indicates that the ouput image will have the same dimensions with initial image)} 17 | 18 | \item{threads}{the number of cores to run in parallel} 19 | } 20 | \value{ 21 | depending on the input, either a matrix or an array 22 | } 23 | \description{ 24 | Rotate an image by angle using the 'nearest' or 'bilinear' method 25 | } 26 | \details{ 27 | This function rotates an image by a user-specified angle 28 | } 29 | \examples{ 30 | 31 | path = system.file("tmp_images", "2.jpg", package = "OpenImageR") 32 | 33 | image = readImage(path) 34 | 35 | r = rotateImage(image, 75, threads = 1) 36 | 37 | } 38 | -------------------------------------------------------------------------------- /man/runUI.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/launcher_shiny.R 3 | \name{runUI} 4 | \alias{runUI} 5 | \title{launcher for the shiny application} 6 | \usage{ 7 | runUI() 8 | } 9 | \description{ 10 | launcher for the shiny application 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sec_gaus_bl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{sec_gaus_bl} 4 | \alias{sec_gaus_bl} 5 | \title{secondary function for downsampling} 6 | \usage{ 7 | sec_gaus_bl(image, factor, sigma, range_gauss) 8 | } 9 | \description{ 10 | secondary function for downsampling 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/sec_resiz_array.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{sec_resiz_array} 4 | \alias{sec_resiz_array} 5 | \title{secondary function for 'resizeImage' [ array ]} 6 | \usage{ 7 | sec_resiz_array(image, flag = T) 8 | } 9 | \description{ 10 | secondary function for 'resizeImage' [ array ] 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/superpixel_bbox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{superpixel_bbox} 4 | \alias{superpixel_bbox} 5 | \title{Bounding box for the superpixel labels} 6 | \usage{ 7 | superpixel_bbox(superpixel_labels, non_overlapping_superpixels = FALSE) 8 | } 9 | \arguments{ 10 | \item{superpixel_labels}{a matrix. The \emph{superpixel_labels} parameter corresponds to the output \emph{labels} of the \emph{superpixels} function} 11 | 12 | \item{non_overlapping_superpixels}{either TRUE or FALSE. If TRUE then besides the (x,y) coordinates of each superpixel-segment (matrix), the overlapping indices for each superpixel will be returned (list). See the details section for more information} 13 | } 14 | \description{ 15 | Bounding box for the superpixel labels 16 | } 17 | \details{ 18 | If the \emph{non_overlapping_superpixels} parameter is set to \emph{FALSE} then : the \emph{superpixel_bbox} function returns the bounding box for the labels of the \emph{superpixels} function. The 19 | output is a matrix which contains the min and max indices of the x-y-coordinates and the corresponding unique superpixel labels. 20 | 21 | If the \emph{non_overlapping_superpixels} parameter is set to \emph{TRUE} then : the \emph{superpixel_bbox} function returns besides the previously explained matrix also the overlapping indices for each 22 | superpixel. These indices can be used to overwrite pixels with a specific value (say 0.0), which might appear in two superpixels simultaneously. This feature might be useful in case a user 23 | intends to use an algorithm and the separability of superpixel-segments is of importance. 24 | 25 | Therefore in both cases overlapping superpixels will be computed, however if the \emph{non_overlapping_superpixels} parameter is set to \emph{TRUE} then also a list of overlapping indices will be returned. 26 | } 27 | \examples{ 28 | 29 | library(OpenImageR) 30 | 31 | 32 | #----------- 33 | # read image 34 | #----------- 35 | 36 | path = system.file("tmp_images", "slic_im.png", package = "OpenImageR") 37 | 38 | im = readImage(path) 39 | 40 | im = im[,, 1:3] 41 | 42 | 43 | #-------------------- 44 | # compute superpixels 45 | #-------------------- 46 | 47 | res = superpixels(input_image = im, method = "slic", superpixel = 200, 48 | 49 | compactness = 20, return_labels = TRUE) 50 | 51 | 52 | #------------------------- 53 | # compute the bounding box 54 | #------------------------- 55 | 56 | bbox = superpixel_bbox(res$labels, non_overlapping_superpixels = FALSE) 57 | 58 | 59 | #------------------------------------------- 60 | # plot the bounding boxes of the superpixels ( for illustration purposes ) 61 | #------------------------------------------- 62 | 63 | 64 | graphics::plot(1:ncol(im), type='n', xlim = c(ncol(im), 1), ylim = c(1, nrow(im))) 65 | 66 | graphics::rasterImage( flipImage(im), 1, 1, ncol(im), nrow(im)) 67 | 68 | 69 | for (i in 1:nrow(bbox)) { 70 | 71 | # the order of the bounding box is c('xmin', 'ymin', 'xmax', 'ymax') 72 | graphics::rect(bbox[i,3], bbox[i,1], bbox[i,4], bbox[i,2], border = "red", lwd = 2) 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /man/superpixel_bbox_subset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{superpixel_bbox_subset} 4 | \alias{superpixel_bbox_subset} 5 | \title{Bounding box for a subset of superpixel labels} 6 | \usage{ 7 | superpixel_bbox_subset(superpixel_labels, superpixel_subset) 8 | } 9 | \arguments{ 10 | \item{superpixel_labels}{a matrix. The \emph{superpixel_labels} parameter corresponds to the output \emph{labels} of the \emph{superpixels} function} 11 | 12 | \item{superpixel_subset}{a numeric or integer vector specifying the subset of superpixel segments.} 13 | } 14 | \description{ 15 | Bounding box for a subset of superpixel labels 16 | } 17 | \details{ 18 | This function should be utilized to return the bounding box for a subset of superpixel segments. To compute the bounding box for all superpixels use the \emph{superpixel_bbox} function. 19 | } 20 | \examples{ 21 | 22 | library(OpenImageR) 23 | 24 | 25 | #----------- 26 | # read image 27 | #----------- 28 | 29 | path = system.file("tmp_images", "slic_im.png", package = "OpenImageR") 30 | 31 | im = readImage(path) 32 | 33 | im = im[,, 1:3] 34 | 35 | 36 | #-------------------- 37 | # compute superpixels 38 | #-------------------- 39 | 40 | res = superpixels(input_image = im, method = "slic", superpixel = 200, 41 | 42 | compactness = 20, return_labels = TRUE) 43 | 44 | 45 | #------------------------- 46 | # compute the bounding box ( for subset of superpixels ) 47 | #------------------------- 48 | 49 | bbox = superpixel_bbox_subset(res$labels, superpixel_subset = c(0, 10, 30)) 50 | 51 | } 52 | -------------------------------------------------------------------------------- /man/superpixels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/superpixels.R 3 | \name{superpixels} 4 | \alias{superpixels} 5 | \title{SLIC and SLICO superpixel implementations} 6 | \usage{ 7 | superpixels( 8 | input_image, 9 | method = "slic", 10 | superpixel = 200, 11 | compactness = 20, 12 | return_slic_data = FALSE, 13 | return_lab_data = FALSE, 14 | return_labels = FALSE, 15 | write_slic = "", 16 | verbose = FALSE 17 | ) 18 | } 19 | \arguments{ 20 | \item{input_image}{either a 2-dimensional or a 3-dimensional input image where the third dimension is equal to 3 (the range of the pixel values should be preferably in the range 0 to 255)} 21 | 22 | \item{method}{a character string specifying the method to use. Either "slic" or "slico"} 23 | 24 | \item{superpixel}{a numeric value specifying the number of superpixels to use} 25 | 26 | \item{compactness}{a numeric value specifying the compactness parameter. The \emph{compactness} parameter is needed only if \emph{method} is "slic". The "slico" method adaptively chooses the compactness parameter for each superpixel differently.} 27 | 28 | \item{return_slic_data}{a boolean. If TRUE then the resulted slic or slico data will be returned} 29 | 30 | \item{return_lab_data}{a boolean. If TRUE then the Lab data will be returned ( the Lab-colour format )} 31 | 32 | \item{return_labels}{a boolean. If TRUE then the labels will be returned} 33 | 34 | \item{write_slic}{a character string. If not an empty string ("") then it should be a path to the output file with extension .bin ( for instance "/my_dir/output.bin" ). The data will be saved in binary format.} 35 | 36 | \item{verbose}{a boolean. If TRUE then information will be printed in the R session} 37 | } 38 | \description{ 39 | SLIC and SLICO superpixel implementations 40 | } 41 | \examples{ 42 | 43 | library(OpenImageR) 44 | 45 | #------------------- 46 | # 3-dimensional data 47 | #------------------- 48 | 49 | path = system.file("tmp_images", "slic_im.png", package = "OpenImageR") 50 | 51 | im = readImage(path) 52 | 53 | res = superpixels(input_image = im, method = "slic", superpixel = 200, 54 | 55 | compactness = 20, return_slic_data = TRUE) 56 | 57 | 58 | #------------------- 59 | # 2-dimensional data 60 | #------------------- 61 | 62 | im_2d = im[,,1] 63 | 64 | res_mt = superpixels(input_image = im_2d, method = "slic", superpixel = 200, 65 | 66 | compactness = 20, return_slic_data = TRUE) 67 | 68 | } 69 | \references{ 70 | https://www.epfl.ch/labs/ivrl/research/slic-superpixels/ 71 | } 72 | -------------------------------------------------------------------------------- /man/switch_filter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{switch_filter} 4 | \alias{switch_filter} 5 | \title{secondary function for edge_detection function} 6 | \usage{ 7 | switch_filter( 8 | kernel, 9 | conv_mod, 10 | gaussian_dims = 5, 11 | sigma = 1, 12 | laplacian_type = 1, 13 | range_gauss = 2 14 | ) 15 | } 16 | \description{ 17 | secondary function for edge_detection function 18 | } 19 | \keyword{internal} 20 | -------------------------------------------------------------------------------- /man/switch_hashing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{switch_hashing} 4 | \alias{switch_hashing} 5 | \title{if-else function for hashing} 6 | \usage{ 7 | switch_hashing( 8 | object, 9 | width, 10 | height, 11 | hash_size, 12 | highfreq_factor, 13 | method, 14 | mode, 15 | threads, 16 | resize 17 | ) 18 | } 19 | \description{ 20 | if-else function for hashing 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/switch_invariant.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash_functions.R 3 | \name{switch_invariant} 4 | \alias{switch_invariant} 5 | \title{secondary function for invariant_hash} 6 | \usage{ 7 | switch_invariant(method, gray_image, MODE, hash_size, highfreq_factor, resize) 8 | } 9 | \description{ 10 | secondary function for invariant_hash 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/translation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{translation} 4 | \alias{translation} 5 | \title{image translation} 6 | \usage{ 7 | translation(image, shift_rows = 0, shift_cols = 0, padded_value = 0) 8 | } 9 | \arguments{ 10 | \item{image}{a matrix, data frame or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{shift_rows}{a positive or negative integer specifying the direction that the rows should be shifted} 13 | 14 | \item{shift_cols}{a positive or negative integer specifying the direction that the columns should be shifted} 15 | 16 | \item{padded_value}{either a numeric value or a numeric vector of length 3 (corresponding to RGB). If it's not equal to 0 then the values of the shifted rows or columns will be filled with the user-defined padded_value} 17 | } 18 | \value{ 19 | a matrix or 3-dimensional array where the third dimension is equal to 3 20 | } 21 | \description{ 22 | shift the position of an image by adding/subtracting a value to/from the X or Y coordinates 23 | } 24 | \details{ 25 | If shift_rows is not zero then the image will be sifted row-wise (upsides or downsides depending on the sign). If shift_cols is not zero then 26 | the image will be sifted column-wise (right or left depending on the sign). 27 | } 28 | \examples{ 29 | 30 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 31 | 32 | image = readImage(path) 33 | 34 | res_tr = translation(image, shift_rows = 10, shift_cols = -10) 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/uniform_filter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/open_image_rscript.R 3 | \name{uniform_filter} 4 | \alias{uniform_filter} 5 | \title{uniform filter (convolution with uniform kernel)} 6 | \usage{ 7 | uniform_filter(image, size, conv_mode = "same") 8 | } 9 | \arguments{ 10 | \item{image}{matrix or 3-dimensional array where the third dimension is equal to 3} 11 | 12 | \item{size}{a 2-item vector specifying the horizontal and vertical dimensions of the uniform kernel, e.g. c(3,3)} 13 | 14 | \item{conv_mode}{the convolution mode should be one of 'same', 'full'} 15 | } 16 | \value{ 17 | depending on the input, either a matrix or an array 18 | } 19 | \description{ 20 | uniform filter (convolution with uniform kernel) 21 | } 22 | \details{ 23 | This function applies a uniform filter to a matrix or to a 3-dimensional array where the third dimension is equal to 3 24 | } 25 | \examples{ 26 | 27 | path = system.file("tmp_images", "1.png", package = "OpenImageR") 28 | 29 | image = readImage(path) 30 | 31 | filt = uniform_filter(image, c(4,4), conv_mode = "same") 32 | 33 | } 34 | \author{ 35 | Lampros Mouselimis 36 | } 37 | -------------------------------------------------------------------------------- /man/verify_image_extension.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/read_image.R 3 | \name{verify_image_extension} 4 | \alias{verify_image_extension} 5 | \title{Verify that the input image extension is valid} 6 | \usage{ 7 | verify_image_extension(image_path, regex_img = "jpe?g|png|tif$|tiff$") 8 | } 9 | \arguments{ 10 | \item{image_path}{a character string specifying the path to the saved image} 11 | 12 | \item{regex_img}{a character string specifying the regex used to verify if the image extension is valid} 13 | } 14 | \value{ 15 | either the image path extension or an error 16 | } 17 | \description{ 18 | Verify that the input image extension is valid 19 | } 20 | \details{ 21 | The OpenImageR package uses the 'readPNG', 'readJPEG' and 'readTIFF' R packages in the background. Thus, only image file path 22 | extensions that can be processed from these R packages should be used as input to the 'readImage' function 23 | } 24 | \examples{ 25 | 26 | vec_img_ext = c('png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'tif', 'TIF', 'tiff', 'TIFF') 27 | 28 | vec_valid = sapply(vec_img_ext, function(x) { 29 | ext_iter = paste(c('example_image', x), collapse = '.') 30 | verify_image_extension(image_path = ext_iter) 31 | }) 32 | 33 | all(vec_img_ext == vec_valid) 34 | } 35 | \references{ 36 | https://github.com/mlampros/OpenImageR/issues/25 37 | } 38 | -------------------------------------------------------------------------------- /man/warpAffine.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/warp_affine.R 3 | \name{warpAffine} 4 | \alias{warpAffine} 5 | \title{Warp Affine} 6 | \usage{ 7 | warpAffine(img, M, R, C, threads = 1, verbose = FALSE) 8 | } 9 | \arguments{ 10 | \item{img}{either a matrix or a 3-dimensional array (where the third dimension is equal to 3) with a range of values between 0 and 255} 11 | 12 | \item{M}{a matrix corresponding to the transformation matrix} 13 | 14 | \item{R}{a value corresponding to the destination number of rows} 15 | 16 | \item{C}{a value corresponding to the destination number of columns} 17 | 18 | \item{threads}{an integer specifying the number of threads to run in parallel. This parameter applies only if the input "img" parameter is of type matrix.} 19 | 20 | \item{verbose}{a boolean. If TRUE then information will be printed in the console} 21 | } 22 | \value{ 23 | either a matrix or a 3-dimensional array (where the third dimension is equal to 3) 24 | } 25 | \description{ 26 | Warp Affine 27 | } 28 | \examples{ 29 | 30 | require(OpenImageR) 31 | 32 | path = system.file("tmp_images", "landscape.jpg", package = "OpenImageR") 33 | img = readImage(path) 34 | img = img * 255 35 | 36 | #............................. 37 | # compute the affine transform 38 | #............................. 39 | 40 | r = ncol(img) 41 | c = nrow(img) 42 | offset = 50 43 | 44 | original_points = matrix(data = c(0, 0, r, 0, 0, c), 45 | nrow = 3, 46 | ncol = 2, 47 | byrow = TRUE) 48 | 49 | transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 50 | nrow = 3, 51 | ncol = 2, 52 | byrow = TRUE) 53 | 54 | M_aff = getAffineTransform(original_points = original_points, 55 | transformed_points = transformed_points) 56 | 57 | #.............. 58 | # 2-dimensional 59 | #.............. 60 | 61 | img_2d = rgb_2gray(img) 62 | 63 | res_2d = warpAffine(img = img_2d, 64 | M = M_aff, 65 | R = r, 66 | C = c, 67 | threads = 1, 68 | verbose = TRUE) 69 | 70 | # imageShow(res_2d) 71 | 72 | #.............. 73 | # 3-dimensional 74 | #.............. 75 | 76 | res_3d = warpAffine(img = img, 77 | M = M_aff, 78 | R = r, 79 | C = c, 80 | verbose = TRUE) 81 | 82 | # imageShow(res_3d) 83 | 84 | } 85 | \references{ 86 | https://github.com/OlehOnyshchak/ImageTransformations/blob/master/AffineTransformation.ipynb 87 | } 88 | -------------------------------------------------------------------------------- /man/writeImage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/write_image.R 3 | \name{writeImage} 4 | \alias{writeImage} 5 | \title{This function writes 2- or 3-dimensional image (where the third dimension is equal to 3) data to a file} 6 | \usage{ 7 | writeImage(data, file_name, ...) 8 | } 9 | \arguments{ 10 | \item{data}{a 2- or 3-dimensional object (matrix, data frame or array where the third dimension is equal to 3)} 11 | 12 | \item{file_name}{a string specifying the name of the new file} 13 | 14 | \item{...}{further arguments for the writePNG, writeJPEG and writeTIFF functions} 15 | } 16 | \value{ 17 | a saved image file 18 | } 19 | \description{ 20 | This function writes 2- or 3-dimensional image (where the third dimension is equal to 3) data to a file. Supported types are .png, .jpeg, .jpg, .tiff (or .tif, .TIFF, .TIF) 21 | } 22 | \details{ 23 | This function takes as input a matrix, data frame or array and saves the data in one of the supported image types ( .png, .jpeg, .jpg, .tiff ). 24 | Extension types similar to .tiff such as .tif, .TIFF, .TIF are also supported 25 | } 26 | \examples{ 27 | 28 | # path = system.file("tmp_images", "1.png", package = "OpenImageR") 29 | 30 | # im = readImage(path) 31 | 32 | # writeImage(im, 'new_image.jpeg') 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_64BIT_WORD 2 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) 3 | PKG_CPPFLAGS = -I../inst/include/ 4 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_64BIT_WORD 2 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) 3 | PKG_CPPFLAGS = -I../inst/include/ 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(OpenImageR) 3 | 4 | test_check("OpenImageR") 5 | -------------------------------------------------------------------------------- /tests/testthat/image_files/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/1.png -------------------------------------------------------------------------------- /tests/testthat/image_files/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/2.jpg -------------------------------------------------------------------------------- /tests/testthat/image_files/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/3.jpeg -------------------------------------------------------------------------------- /tests/testthat/image_files/4.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/4.tiff -------------------------------------------------------------------------------- /tests/testthat/image_files/HOG_apply_folder/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/HOG_apply_folder/1.png -------------------------------------------------------------------------------- /tests/testthat/image_files/HOG_apply_folder/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/HOG_apply_folder/10.png -------------------------------------------------------------------------------- /tests/testthat/image_files/HOG_apply_folder/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/HOG_apply_folder/4.png -------------------------------------------------------------------------------- /tests/testthat/image_files/HOG_apply_folder/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/HOG_apply_folder/5.png -------------------------------------------------------------------------------- /tests/testthat/image_files/HOG_apply_folder/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/HOG_apply_folder/8.png -------------------------------------------------------------------------------- /tests/testthat/image_files/invalid_image/invalid_image.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/tests/testthat/image_files/invalid_image/invalid_image.inv -------------------------------------------------------------------------------- /tests/testthat/test-crop_image.R: -------------------------------------------------------------------------------- 1 | context("Crop image") 2 | 3 | # crop_image_secondary function 4 | 5 | testthat::test_that("the crop_image_secondary function returns an error if height and width is greater than the initial dimensions of the image", { 6 | 7 | out_array = matrix(runif(100), 10, 10) 8 | 9 | testthat::expect_error(crop_image_secondary(out_array, 11, 11)) 10 | }) 11 | 12 | 13 | testthat::test_that("the crop_image_secondary function returns the correct dimensions of the output image", { 14 | 15 | out_array = matrix(runif(100), 10, 10) 16 | 17 | height = 5 18 | width = 5 19 | 20 | res = crop_image_secondary(out_array, height, width) 21 | 22 | testthat::expect_true(dim(res)[2] == height && dim(res)[1] == width) 23 | }) 24 | 25 | # cropImage function 26 | 27 | 28 | testthat::test_that("the cropImage function returns an error if height, width are not given", { 29 | 30 | out_array = matrix(runif(100), 10, 10) 31 | 32 | height = NULL 33 | width = NULL 34 | 35 | testthat::expect_error(cropImage(out_array, width, height, type = 'equal_spaced')) 36 | }) 37 | 38 | 39 | testthat::test_that("the cropImage function returns an error if the type is incorrect", { 40 | 41 | out_array = matrix(runif(100), 10, 10) 42 | 43 | height = 5 44 | width = 5 45 | 46 | testthat::expect_error(cropImage(out_array, width, height, type = NULL)) 47 | }) 48 | 49 | 50 | testthat::test_that("the cropImage function returns an error if the type is incorrect", { 51 | 52 | out_array = matrix(runif(100), 10, 10) 53 | 54 | height = 5 55 | width = 5 56 | 57 | testthat::expect_error(cropImage(out_array, width, height, type = 'NULL')) 58 | }) 59 | 60 | 61 | testthat::test_that("the cropImage function returns an error if height and width are not are not of type numeric", { 62 | 63 | out_array = matrix(runif(100), 10, 10) 64 | 65 | height = list(1, 5) 66 | width = list(1, 5) 67 | 68 | testthat::expect_error(cropImage(out_array, width, height, type = 'equal_spaced')) 69 | }) 70 | 71 | 72 | testthat::test_that("the cropImage function returns an error if height and width are not are not of type numeric", { 73 | 74 | out_array = matrix(runif(100), 10, 10) 75 | 76 | height = matrix(5) 77 | width = matrix(5) 78 | 79 | testthat::expect_error(cropImage(out_array, width, height, type = 'equal_spaced')) 80 | }) 81 | 82 | 83 | testthat::test_that("the cropImage function returns an error if height and width are not are not of type numeric", { 84 | 85 | out_array = matrix(runif(100), 10, 10) 86 | 87 | height = data.frame(5) 88 | width = data.frame(5) 89 | 90 | testthat::expect_error(cropImage(out_array, width, height, type = 'equal_spaced')) 91 | }) 92 | 93 | 94 | testthat::test_that("the cropImage function returns an error if the type is equal_spaced and height and width are not of length 1", { 95 | 96 | out_array = matrix(runif(100), 10, 10) 97 | 98 | height = c(1:5) 99 | width = c(1:5) 100 | 101 | testthat::expect_error(cropImage(out_array, width, height, type = 'equal_spaced')) 102 | }) 103 | 104 | 105 | testthat::test_that("the cropImage function returns an error if the type is user_defined and height and width are of length 1", { 106 | 107 | out_array = matrix(runif(100), 10, 10) 108 | 109 | height = 5 110 | width = 5 111 | 112 | testthat::expect_error(cropImage(out_array, width, height, type = 'user_defined')) 113 | }) 114 | 115 | 116 | testthat::test_that("the cropImage function returns an error if the type is user_defined and data is not an array or matrix", { 117 | 118 | out_array = list(matrix(runif(100), 10, 10)) 119 | 120 | height = 1:5 121 | width = 1:5 122 | 123 | testthat::expect_error(cropImage(out_array, width, height, type = 'user_defined')) 124 | }) 125 | 126 | 127 | testthat::test_that("the cropImage function returns an error if the type is equal_spaced and data is not an array or matrix", { 128 | 129 | out_array = list(matrix(runif(100), 10, 10)) 130 | 131 | height = 5 132 | width = 5 133 | 134 | testthat::expect_error(cropImage(out_array, width, height, type = 'equal_spaced')) 135 | }) 136 | 137 | 138 | testthat::test_that("the cropImage function returns a matrix with the correct dimensions if the type is equal_spaced ", { 139 | 140 | out_array = matrix(runif(100), 10, 10) 141 | 142 | height = 5 143 | width = 5 144 | 145 | res = cropImage(out_array, width, height, type = 'equal_spaced') 146 | 147 | testthat::expect_true(is.matrix(res) && ncol(res) == height && nrow(res) == width) 148 | }) 149 | 150 | 151 | testthat::test_that("the cropImage function returns a matrix with the correct dimensions if the type is user_defined ", { 152 | 153 | out_array = matrix(runif(100), 10, 10) 154 | 155 | height = 1:5 156 | width = 1:6 157 | 158 | res = cropImage(out_array, width, height, type = 'user_defined') 159 | 160 | testthat::expect_true(is.matrix(res) && ncol(res) == length(height) && nrow(res) == length(width)) 161 | }) 162 | 163 | 164 | testthat::test_that("the cropImage function returns a matrix with the correct dimensions if the type is equal_spaced ", { 165 | 166 | out_array = array(runif(300), dim = c(10, 10, 3)) 167 | 168 | height = 5 169 | width = 5 170 | 171 | res = cropImage(out_array, width, height, type = 'equal_spaced') 172 | 173 | testthat::expect_true(is.array(res) && mean(apply(res, 3, ncol)) == height && mean(apply(res, 3, nrow)) == width) 174 | }) 175 | 176 | 177 | testthat::test_that("the cropImage function returns a matrix with the correct dimensions if the type is user_defined ", { 178 | 179 | out_array = array(runif(300), dim = c(10, 10, 3)) 180 | 181 | height = 1:5 182 | width = 1:6 183 | 184 | res = cropImage(out_array, width, height, type = 'user_defined') 185 | 186 | testthat::expect_true(is.array(res) && mean(apply(res, 3, ncol)) == length(height) && mean(apply(res, 3, nrow)) == length(width)) 187 | }) 188 | -------------------------------------------------------------------------------- /tests/testthat/test-delation_erosion.R: -------------------------------------------------------------------------------- 1 | MATR = matrix(runif(1000), 100, 100) 2 | 3 | DF = as.data.frame(MATR) 4 | 5 | ARRAY = array(unlist(list(matrix(runif(1000), 100, 100), matrix(runif(1000), 100, 100), matrix(runif(1000), 100, 100))), dim = c(100, 100, 3)) 6 | 7 | 8 | context('Deletion and erosion tests') 9 | 10 | 11 | testthat::test_that("the function dilationErosion returns an error if the threads is less than 1", { 12 | 13 | testthat::expect_error( dilationErosion(MATR, c(3,3), method = 'dilation', threads = 0) ) 14 | }) 15 | 16 | testthat::test_that("the function dilationErosion returns an error if the method is invalid", { 17 | 18 | testthat::expect_error( dilationErosion(MATR, c(3,3), method = 'invalid', threads = 1) ) 19 | }) 20 | 21 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 22 | 23 | testthat::expect_error( dilationErosion(MATR, list(c(3,3)), method = 'dilation', threads = 1) ) 24 | }) 25 | 26 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 27 | 28 | testthat::expect_error( dilationErosion(MATR, c(0,3), method = 'dilation', threads = 1) ) 29 | }) 30 | 31 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 32 | 33 | testthat::expect_error( dilationErosion(MATR, c(3,0), method = 'dilation', threads = 1) ) 34 | }) 35 | 36 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 37 | 38 | testthat::expect_error( dilationErosion(MATR, c(nrow(MATR),3), method = 'dilation', threads = 1) ) 39 | }) 40 | 41 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 42 | 43 | testthat::expect_error( dilationErosion(MATR, c(4,ncol(MATR)), method = 'dilation', threads = 1) ) 44 | }) 45 | 46 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 47 | 48 | testthat::expect_error( dilationErosion(MATR, c(4,3,5), method = 'dilation', threads = 1) ) 49 | }) 50 | 51 | testthat::test_that("the function dilationErosion returns an error if the filter isn't in the correct form", { 52 | 53 | testthat::expect_error( dilationErosion(MATR, c('4','3'), method = 'dilation', threads = 1) ) 54 | }) 55 | 56 | testthat::test_that("the function dilationErosion returns an error if the image isn't one of matrix , data frame or array", { 57 | 58 | testthat::expect_error( dilationErosion(list(MATR), c(4,4), method = 'dilation', threads = 1) ) 59 | }) 60 | 61 | testthat::test_that("the function dilationErosion takes a data frame as input and returns a matrix, method = 'dilation'", { 62 | 63 | res = dilationErosion(as.data.frame(MATR), c(4,4), method = 'dilation', threads = 1) 64 | 65 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(MATR) && ncol(res) == ncol(MATR) ) 66 | }) 67 | 68 | testthat::test_that("the function dilationErosion takes a matrix as input and returns a matrix, method = 'dilation'", { 69 | 70 | res = dilationErosion(MATR, c(4,4), method = 'dilation', threads = 1) 71 | 72 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(MATR) && ncol(res) == ncol(MATR) ) 73 | }) 74 | 75 | testthat::test_that("the function dilationErosion takes a matrix as input and returns a matrix, method = 'dilation'", { 76 | 77 | res = dilationErosion(ARRAY, c(4,4), method = 'dilation', threads = 1) 78 | 79 | testthat::expect_true( is.array(res) && nrow(res) == nrow(ARRAY) && ncol(res) == ncol(ARRAY) && length(dim(ARRAY)) == length(dim(res)) ) 80 | }) 81 | 82 | 83 | testthat::test_that("the function dilationErosion takes a data frame as input and returns a matrix, method = 'erosion'", { 84 | 85 | res = dilationErosion(as.data.frame(MATR), c(4,4), method = 'erosion', threads = 1) 86 | 87 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(MATR) && ncol(res) == ncol(MATR) ) 88 | }) 89 | 90 | testthat::test_that("the function dilationErosion takes a matrix as input and returns a matrix, method = 'erosion'", { 91 | 92 | res = dilationErosion(MATR, c(4,4), method = 'erosion', threads = 1) 93 | 94 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(MATR) && ncol(res) == ncol(MATR) ) 95 | }) 96 | 97 | testthat::test_that("the function dilationErosion takes a matrix as input and returns a matrix, method = 'erosion'", { 98 | 99 | res = dilationErosion(ARRAY, c(4,4), method = 'erosion', threads = 1) 100 | 101 | testthat::expect_true( is.array(res) && nrow(res) == nrow(ARRAY) && ncol(res) == ncol(ARRAY) && length(dim(ARRAY)) == length(dim(res)) ) 102 | }) 103 | 104 | testthat::test_that("the function dilationErosion takes a matrix as input and returns a matrix, method = 'erosion', RANGE of values between 0 and 255", { 105 | 106 | MATR1 = matrix(sample(c(0,255), 10000, replace = T), 100, 100) 107 | 108 | res = dilationErosion(MATR1, c(4,4), method = 'erosion', threads = 1) 109 | 110 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(MATR) && ncol(res) == ncol(MATR) ) 111 | }) 112 | -------------------------------------------------------------------------------- /tests/testthat/test-down_sample_blur.R: -------------------------------------------------------------------------------- 1 | context('Down sample using gaussian blur') 2 | 3 | 4 | testthat::test_that("in case of an array input (image) the down_sample_image function returns an array", { 5 | 6 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 7 | 8 | testthat::expect_true(is.array(down_sample_image(image_array, 2, T))) 9 | }) 10 | 11 | 12 | testthat::test_that("in case of an array input (image) the down_sample_image function returns an array, if gaussian_blur = FALSE", { 13 | 14 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 15 | 16 | testthat::expect_true(is.array(down_sample_image(image_array, 2, F))) 17 | }) 18 | 19 | testthat::test_that("in case of a matrix input (image) the down_sample_image function returns an matrix", { 20 | 21 | image_array = matrix(runif(25), 5, 5) 22 | 23 | testthat::expect_true(is.matrix(down_sample_image(image_array, 2, T))) 24 | }) 25 | 26 | 27 | testthat::test_that("in case of a matrix input (image) the down_sample_image function returns an matrix, if gaussian_blur = FALSE", { 28 | 29 | image_array = matrix(runif(25), 5, 5) 30 | 31 | testthat::expect_true(is.matrix(down_sample_image(image_array, 2, T))) 32 | }) 33 | 34 | 35 | testthat::test_that("in case of a data frame input (image) the down_sample_image function returns an matrix", { 36 | 37 | image_array = as.data.frame(matrix(runif(25), 5, 5)) 38 | 39 | testthat::expect_true( inherits(down_sample_image(image_array, 2, F), 'matrix') ) 40 | }) 41 | 42 | 43 | testthat::test_that("in case of a factor less than 1 it returns an error", { 44 | 45 | image_array = matrix(runif(25), 5, 5) 46 | 47 | testthat::expect_error(down_sample_image(image_array, factor = 0.5, gaussian_blur = T)) 48 | }) 49 | 50 | testthat::test_that("in case of gaussian_blur = TRUE it returns an error", { 51 | 52 | image_array = matrix(runif(25), 5, 5) 53 | 54 | testthat::expect_error(down_sample_image(image_array, 2, gaussian_blur = NULL)) 55 | }) 56 | 57 | testthat::test_that("in case of an false range_gauss it returns an error", { 58 | 59 | image_array = matrix(runif(25), 5, 5) 60 | 61 | testthat::expect_error(down_sample_image(image_array, 2, gaussian_blur = T, range_gauss = 0)) 62 | }) 63 | 64 | 65 | testthat::test_that("in case of a false image input it returns an error", { 66 | 67 | image_array = list(matrix(runif(25), 5, 5)) 68 | 69 | testthat::expect_error(down_sample_image(image_array, factor = 2, gaussian_blur = T, range_gauss = 1.0)) 70 | }) 71 | 72 | -------------------------------------------------------------------------------- /tests/testthat/test-edge_detection.R: -------------------------------------------------------------------------------- 1 | context('Edge detection function') 2 | 3 | 4 | testthat::test_that("in case of an array input (image) the edge detection function returns an array", { 5 | 6 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 7 | 8 | testthat::expect_true(is.array(edge_detection(image_array, method = 'LoG', conv_mode = 'same', approx = T, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1))) 9 | }) 10 | 11 | testthat::test_that("in case of a matrix input (image) the edge detection function returns a matrix", { 12 | 13 | image_array = matrix(runif(25), 5, 5) 14 | 15 | testthat::expect_true( inherits(edge_detection(image_array, method = 'LoG', conv_mode = 'same', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1), 'matrix') ) 16 | }) 17 | 18 | 19 | testthat::test_that("in case of a NULL method returns an error", { 20 | 21 | image_array = matrix(runif(25), 5, 5) 22 | 23 | testthat::expect_error(edge_detection(image_array, method = NULL, conv_mode = 'same', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1)) 24 | }) 25 | 26 | 27 | testthat::test_that("in case of an unknown method returns an error", { 28 | 29 | image_array = matrix(runif(25), 5, 5) 30 | 31 | testthat::expect_error(edge_detection(image_array, method = 'some_unknown_method', conv_mode = 'same', approx = T, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1)) 32 | }) 33 | 34 | testthat::test_that("in case that the 'conv_mode' argument is NULL it returns an error", { 35 | 36 | image_array = matrix(runif(25), 5, 5) 37 | 38 | testthat::expect_error(edge_detection(image_array, method = 'LoG', conv_mode = NULL, approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1)) 39 | }) 40 | 41 | 42 | testthat::test_that("in case that the 'conv_mode' argument is not one of 'same', 'full' it returns an error", { 43 | 44 | image_array = matrix(runif(25), 5, 5) 45 | 46 | testthat::expect_error(edge_detection(image_array, method = 'LoG', conv_mode = 'invalid', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1)) 47 | }) 48 | 49 | 50 | testthat::test_that("in case that the 'approx' argument is not a boolean it returns an error", { 51 | 52 | image_array = matrix(runif(25), 5, 5) 53 | 54 | testthat::expect_error(edge_detection(image_array, method = 'LoG', conv_mode = 'same', approx = NULL, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1)) 55 | }) 56 | 57 | testthat::test_that("in case that the image-data is not a matrix or an array it returns an error", { 58 | 59 | image_array = list(matrix(runif(25), 5, 5)) 60 | 61 | testthat::expect_error(edge_detection(image_array, method = 'LoG', conv_mode = 'same', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1)) 62 | }) 63 | 64 | 65 | # test various kernel filter 66 | 67 | 68 | testthat::test_that("in case of an array input (image) the edge detection function returns an array", { 69 | 70 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 71 | 72 | testthat::expect_true(is.array(edge_detection(image_array, method = 'Sobel', conv_mode = 'same', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1))) 73 | }) 74 | 75 | testthat::test_that("in case of an array input (image) the edge detection function returns an array", { 76 | 77 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 78 | 79 | testthat::expect_true(is.array(edge_detection(image_array, method = 'Prewitt', conv_mode = 'same', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1))) 80 | }) 81 | 82 | testthat::test_that("in case of an matrix input (image) the edge detection function returns a matrix", { 83 | 84 | image_array = matrix(runif(25), 5, 5) 85 | 86 | testthat::expect_true( inherits(edge_detection(image_array, method = 'Roberts_cross', conv_mode = 'same', approx = T, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1), 'matrix') ) 87 | }) 88 | 89 | 90 | testthat::test_that("in case of an data frame input (image) the edge detection function returns a matrix", { 91 | 92 | image_array = as.data.frame(matrix(runif(25), 5, 5)) 93 | 94 | testthat::expect_true( inherits(edge_detection(image_array, method = 'Roberts_cross', conv_mode = 'full', approx = T, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1), 'matrix') ) 95 | }) 96 | 97 | testthat::test_that("in case of an array input (image) the edge detection function returns an array", { 98 | 99 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 100 | 101 | testthat::expect_true(is.array(edge_detection(image_array, method = 'Frei_chen', conv_mode = 'same', approx = F, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1))) 102 | }) 103 | 104 | 105 | testthat::test_that("in case of an array input (image) the edge detection function returns an array", { 106 | 107 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 108 | 109 | testthat::expect_true(is.array(edge_detection(image_array, method = 'Scharr', conv_mode = 'full', approx = T, gaussian_dims = 5, sigma = 1.0, range_gauss = 2, laplacian_type = 1))) 110 | }) 111 | -------------------------------------------------------------------------------- /tests/testthat/test-flip_zca_image.R: -------------------------------------------------------------------------------- 1 | 2 | MATR = matrix(runif(1000), 100, 100) 3 | 4 | DF = as.data.frame(MATR) 5 | 6 | ARRAY = array(unlist(list(matrix(runif(1000), 100, 100), matrix(runif(1000), 100, 100), matrix(runif(1000), 100, 100))), dim = c(100, 100, 3)) 7 | 8 | 9 | context('Flip and zca whiten image') 10 | 11 | 12 | # flip image 13 | 14 | testthat::test_that("the function flipImage returns an error if mode is invalid", { 15 | 16 | testthat::expect_error( flipImage(MATR, mode = 'invalid') ) 17 | }) 18 | 19 | 20 | testthat::test_that("the function flipImage returns an error if image type is invalid", { 21 | 22 | testthat::expect_error( flipImage(list(MATR), mode = 'horizontal') ) 23 | }) 24 | 25 | 26 | testthat::test_that("the function flipImage takes a matrix and returns a matrix of the same dimensions", { 27 | 28 | res = flipImage(MATR, mode = 'horizontal') 29 | 30 | testthat::expect_true( is.matrix(res) && ncol(res) == ncol(MATR) && nrow(res) == nrow(MATR) ) 31 | }) 32 | 33 | 34 | testthat::test_that("the function flipImage takes a data frame and returns a matrix of the same dimensions", { 35 | 36 | res = flipImage(as.data.frame(MATR), mode = 'horizontal') 37 | 38 | testthat::expect_true( is.matrix(res) && ncol(res) == ncol(MATR) && nrow(res) == nrow(MATR) ) 39 | }) 40 | 41 | 42 | testthat::test_that("the function flipImage takes an array and returns an array of the same dimensions", { 43 | 44 | res = flipImage(ARRAY, mode = 'vertical') 45 | 46 | testthat::expect_true( is.array(res) && mean(apply(res, 3, ncol)) == ncol(ARRAY[,,1]) && mean(apply(res, 3, nrow)) == nrow(ARRAY[,,1]) ) 47 | }) 48 | 49 | 50 | 51 | # zca whitening 52 | 53 | 54 | testthat::test_that("the function ZCAwhiten returns an error if epsilon is negative", { 55 | 56 | testthat::expect_error( ZCAwhiten(MATR, k = 5, epsilon = -0.1) ) 57 | }) 58 | 59 | 60 | testthat::test_that("the function ZCAwhiten returns an error if k is negative, and image is matrix", { 61 | 62 | testthat::expect_error( ZCAwhiten(MATR, k = -1, epsilon = 0.1) ) 63 | }) 64 | 65 | 66 | testthat::test_that("the function ZCAwhiten returns an error if k is negative, and image is ARRAY", { 67 | 68 | testthat::expect_error( ZCAwhiten(ARRAY, k = -1, epsilon = 0.1) ) 69 | }) 70 | 71 | 72 | testthat::test_that("the function ZCAwhiten returns an error if k greater than the number of columns, and image is matrix", { 73 | 74 | testthat::expect_error( ZCAwhiten(MATR, k = ncol(MATR) + 1, epsilon = 0.1) ) 75 | }) 76 | 77 | 78 | testthat::test_that("the function ZCAwhiten returns an error if k greater than the number of columns, and image is ARRAY", { 79 | 80 | testthat::expect_error( ZCAwhiten(ARRAY, k = ncol(MATR) + 1, epsilon = 0.1) ) 81 | }) 82 | 83 | 84 | testthat::test_that("the function ZCAwhiten returns an error the image type is invalid", { 85 | 86 | testthat::expect_error( ZCAwhiten(list(ARRAY), k = ncol(MATR) + 1, epsilon = 0.1) ) 87 | }) 88 | 89 | 90 | testthat::test_that("the function ZCAwhiten takes a data frame and returns a matrix with the correct dimensions", { 91 | 92 | res = ZCAwhiten(as.data.frame(MATR), k = 10, epsilon = 0.1) 93 | 94 | testthat::expect_true( is.matrix(res) && ncol(MATR) == ncol(res) && nrow(MATR) == nrow(res) ) 95 | }) 96 | 97 | 98 | testthat::test_that("the function ZCAwhiten takes a matrix and returns a matrix with the correct dimensions", { 99 | 100 | res = ZCAwhiten(MATR, k = 10, epsilon = 0.1) 101 | 102 | testthat::expect_true( is.matrix(res) && ncol(MATR) == ncol(res) && nrow(MATR) == nrow(res) ) 103 | }) 104 | 105 | 106 | testthat::test_that("the function ZCAwhiten takes an array and returns an array with the correct dimensions", { 107 | 108 | res = ZCAwhiten(ARRAY, k = 10, epsilon = 0.1) 109 | 110 | testthat::expect_true( is.array(res) && mean(apply(res, 3, ncol)) == ncol(ARRAY[,,1]) && mean(apply(res, 3, nrow)) == nrow(ARRAY[,,1]) ) 111 | }) 112 | -------------------------------------------------------------------------------- /tests/testthat/test-gamma_threshold.R: -------------------------------------------------------------------------------- 1 | context('Gamma threshold functions') 2 | 3 | # thresholding 4 | 5 | 6 | testthat::test_that("image thresholding works as expected", { 7 | 8 | pth_im = system.file("tmp_images", "car.png", package = "OpenImageR") 9 | 10 | im = readImage(pth_im) 11 | 12 | thr = image_thresholding(im, thresh = 0.5) 13 | 14 | testthat::expect_true( inherits(thr, 'matrix') && nrow(im) == nrow(thr) && ncol(im) == ncol(thr) ) 15 | }) 16 | 17 | 18 | testthat::test_that("in case that the 'thresh' parameter is less than or equal to 0.0 it returns an error", { 19 | 20 | image_array = matrix(runif(25), 5, 5) 21 | 22 | testthat::expect_error(image_thresholding(image_array, thresh = 0.0)) 23 | }) 24 | 25 | 26 | testthat::test_that("in case that image is not an array or matrix it returns an error", { 27 | 28 | image_array = list(image_array = matrix(runif(25), 5, 5)) 29 | 30 | testthat::expect_error(image_thresholding(image_array, thresh = 0.5)) 31 | }) 32 | 33 | 34 | testthat::test_that("in case that image is a data frame it returns a matrix", { 35 | 36 | image_array = as.data.frame(matrix(runif(25), 5, 5)) 37 | 38 | testthat::expect_true(is.matrix(image_thresholding(image_array, thresh = 0.5))) 39 | }) 40 | 41 | testthat::test_that("in case that image is a matrix it returns a matrix", { 42 | 43 | image_array = matrix(runif(25), 5, 5) 44 | 45 | testthat::expect_true(is.matrix(image_thresholding(image_array, thresh = 0.5))) 46 | }) 47 | 48 | testthat::test_that("in case that image is an array it returns a matrix", { 49 | 50 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 51 | 52 | testthat::expect_true(is.matrix(image_thresholding(image_array, thresh = 0.5))) 53 | }) 54 | 55 | # gamma correction 56 | 57 | testthat::test_that("in case that image is not an array or matrix it returns an error", { 58 | 59 | image_array = list(image_array = matrix(runif(25), 5, 5)) 60 | 61 | testthat::expect_error(gamma_correction(image_array, gamma = 1.5)) 62 | }) 63 | 64 | testthat::test_that("in case that image is an array it returns an array", { 65 | 66 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 67 | 68 | testthat::expect_true(is.array(gamma_correction(image_array, gamma = 1.5))) 69 | }) 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/testthat/test-gaussian_kernel.R: -------------------------------------------------------------------------------- 1 | context("Create gaussian kernel") 2 | 3 | 4 | testthat::test_that("it returns a matrix", { 5 | 6 | testthat::expect_true(is.matrix(gaussian_kernel(4))) 7 | }) 8 | 9 | 10 | testthat::test_that("the image dimensions match the 'xy_length' argument", { 11 | 12 | xy_length = 5 13 | 14 | tmp = dim(gaussian_kernel(xy_length)) 15 | 16 | testthat::expect_true(all(tmp == xy_length)) 17 | }) 18 | 19 | 20 | testthat::test_that("the 'xy_length' argument is an integer greater than 0", { 21 | 22 | xy_length = 0 23 | 24 | testthat::expect_error(gaussian_kernel(xy_length)) 25 | }) 26 | 27 | 28 | testthat::test_that("the 'range_gauss' argument is greater or equal to 0.0", { 29 | 30 | xy_length = 5 31 | 32 | range_gauss = 0.0 33 | 34 | testthat::expect_error(gaussian_kernel(xy_length, range_gauss = range_gauss)) 35 | }) -------------------------------------------------------------------------------- /tests/testthat/test-hog_features.R: -------------------------------------------------------------------------------- 1 | 2 | MATR = matrix(100, 10, 10) 3 | 4 | DF = as.data.frame(MATR) 5 | 6 | ARRAY = array(unlist(list(matrix(runif(100), 10, 10), matrix(runif(100), 10, 10), matrix(runif(100), 10, 10))), dim = c(10, 10, 3)) 7 | 8 | 9 | context("Hog descriptors") 10 | 11 | 12 | # HOG - function 13 | 14 | testthat::test_that("if the input is a matrix it returns a vector of length cells ^ 2 * orientations ", { 15 | 16 | cls = 3 17 | ornt = 6 18 | 19 | res = HOG(MATR, cells = cls, orientations = ornt) 20 | 21 | testthat::expect_true( is.vector(res) && length(res) == cls ^ 2 * ornt ) 22 | }) 23 | 24 | 25 | testthat::test_that("if the input is a data frame it returns a vector of length cells ^ 2 * orientations ", { 26 | 27 | cls = 3 28 | ornt = 6 29 | 30 | res = HOG(DF, cells = cls, orientations = ornt) 31 | 32 | testthat::expect_true( is.vector(res) && length(res) == cls ^ 2 * ornt ) 33 | }) 34 | 35 | 36 | testthat::test_that("if the input is an array it returns a vector of length cells ^ 2 * orientations ", { 37 | 38 | cls = 3 39 | ornt = 6 40 | 41 | res = HOG(ARRAY, cells = cls, orientations = ornt) 42 | 43 | testthat::expect_true( is.vector(res) && length(res) == cls ^ 2 * ornt ) 44 | }) 45 | 46 | 47 | testthat::test_that("if the input is INVALID it returns an error", { 48 | 49 | cls = 3 50 | ornt = 6 51 | 52 | testthat::expect_error( HOG(list(MATR), cells = cls, orientations = ornt) ) 53 | }) 54 | 55 | 56 | 57 | # func_transform - function 58 | 59 | testthat::test_that("the func_transform function loads a .png image successfully and returns the correct dimensions", { 60 | 61 | path = paste0(getwd(), path.expand("/image_files/")) 62 | 63 | lst_files = list.files(path) 64 | 65 | image_1 = lst_files[1] # load .png image 66 | 67 | fl = strsplit(image_1, '[.]')[[1]][2] 68 | 69 | is_gray = func_transform(image_1, path, fl, T) 70 | 71 | testthat::expect_true( length(dim(is_gray)) == 2 && sum(dim(is_gray)) != 0) 72 | }) 73 | 74 | 75 | testthat::test_that("the func_transform function loads a .jpg image successfully and returns the correct dimensions", { 76 | 77 | path = paste0(getwd(), path.expand("/image_files/")) 78 | 79 | lst_files = list.files(path) 80 | 81 | image_1 = lst_files[2] # load .jpg image 82 | 83 | fl = strsplit(image_1, '[.]')[[1]][2] 84 | 85 | is_gray = func_transform(image_1, path, fl, T) 86 | 87 | testthat::expect_true( length(dim(is_gray)) == 2 && sum(dim(is_gray)) != 0) 88 | }) 89 | 90 | 91 | testthat::test_that("the func_transform function loads a .jpeg image successfully and returns the correct dimensions", { 92 | 93 | path = paste0(getwd(), path.expand("/image_files/")) 94 | 95 | lst_files = list.files(path) 96 | 97 | image_1 = lst_files[3] # load .jpeg image 98 | 99 | fl = strsplit(image_1, '[.]')[[1]][2] 100 | 101 | is_gray = func_transform(image_1, path, fl, T) 102 | 103 | testthat::expect_true( length(dim(is_gray)) == 2 && sum(dim(is_gray)) != 0) 104 | }) 105 | 106 | 107 | testthat::test_that("the func_transform function loads a .tiff image successfully and returns the correct dimensions", { 108 | 109 | path = paste0(getwd(), path.expand("/image_files/")) 110 | 111 | lst_files = list.files(path) 112 | 113 | image_1 = lst_files[4] # load .tiff image 114 | 115 | fl = strsplit(image_1, '[.]')[[1]][2] 116 | 117 | is_gray = func_transform(image_1, path, fl, F) 118 | 119 | testthat::expect_true( length(dim(is_gray)) == 2 && sum(dim(is_gray)) != 0) 120 | }) 121 | 122 | 123 | testthat::test_that("the func_transform function returns an error for an invalid image type", { 124 | 125 | image_1 = 'invalid.inv' 126 | 127 | fl = 'inv' 128 | 129 | testthat::expect_error( func_transform(image_1, path, fl, T) ) 130 | }) 131 | 132 | 133 | # HOG_apply - function 134 | 135 | # error - handling 136 | 137 | testthat::test_that("the HOG_apply function returns an error if threads less than 1", { 138 | 139 | testthat::expect_error( HOG_apply(ARRAY, cells = 2, orientations = 2, rows = NULL, columns = NULL, threads = 0) ) 140 | }) 141 | 142 | 143 | testthat::test_that("the HOG_apply function returns an error if object is a matrix and columns or rows are NULL", { 144 | 145 | testthat::expect_error( HOG_apply(MATR, cells = 2, orientations = 2, rows = NULL, columns = NULL, threads = 1) ) 146 | }) 147 | 148 | 149 | testthat::test_that("the HOG_apply function returns an error if the cells or orientations are less than 1", { 150 | 151 | testthat::expect_error( HOG_apply(ARRAY, cells = 0, orientations = 2, rows = NULL, columns = NULL, threads = 1) ) 152 | }) 153 | 154 | 155 | testthat::test_that("the HOG_apply function returns an error if the path is incorrect (it lacks a slash)", { 156 | 157 | path = paste0(getwd(), path.expand("/image_files")) 158 | 159 | testthat::expect_error( HOG_apply(path, cells = 2, orientations = 2, rows = NULL, columns = NULL, threads = 1) ) 160 | }) 161 | 162 | 163 | testthat::test_that("the HOG_apply function returns an error if the path is correct but the image type is invalid", { 164 | 165 | path = paste0(getwd(), path.expand("/image_files/invalid_image/")) 166 | 167 | testthat::expect_error( HOG_apply(path, cells = 2, orientations = 2, rows = NULL, columns = NULL, threads = 1) ) 168 | }) 169 | 170 | 171 | testthat::test_that("the HOG_apply function returns an error if the input object is not one of the supported types", { 172 | 173 | testthat::expect_error( HOG_apply(list(MATR), cells = 2, orientations = 2, rows = NULL, columns = NULL, threads = 1) ) 174 | }) 175 | 176 | 177 | testthat::test_that("the HOG_apply function returns an error if each row of the input is not equal to rows * columns", { 178 | 179 | NROW = 5 180 | NCOL = 25 181 | tmp_x = matrix(runif(NROW * NCOL), ncol = NCOL, nrow = NROW) 182 | 183 | testthat::expect_error( HOG_apply(tmp_x, cells = 3, orientations = 5, rows = 5, columns = 6, threads = 1) ) 184 | }) 185 | 186 | 187 | # HOG_apply function 188 | 189 | 190 | testthat::test_that("the HOG_apply function returns a list of length 2 when the input object is a path to a folder of images", { 191 | 192 | path = paste0(getwd(), path.expand("/image_files/HOG_apply_folder/")) 193 | 194 | len = list.files(path) 195 | 196 | cls = 3 197 | ornt = 6 198 | 199 | res = HOG_apply(path, cells = cls, orientations = ornt, rows = NULL, columns = NULL, threads = 1) 200 | 201 | testthat::expect_true( length(res) == 2 && length(len) == nrow(res$hog) && cls ^ 2 * ornt == ncol(res$hog) && sum(len %in% res$files) == length(len) ) 202 | }) 203 | 204 | 205 | 206 | testthat::test_that("the HOG_apply function returns a matrix when the input object is a matrix", { 207 | 208 | img_height = 10 209 | img_width = 10 210 | 211 | matrix1 = matrix(runif(1000), img_height ^ 2, img_width ^ 2) 212 | 213 | cls = 3 214 | ornt = 6 215 | 216 | res = HOG_apply(matrix1, cells = cls, orientations = ornt, rows = img_width, columns = img_height, threads = 1) 217 | 218 | testthat::expect_true( nrow(res) == nrow(matrix1) && cls ^ 2 * ornt == ncol(res) ) 219 | }) 220 | 221 | 222 | 223 | testthat::test_that("the HOG_apply function returns a matrix when the input object is an array", { 224 | 225 | img_height = 10 226 | img_width = 10 227 | 228 | ARRAY1 = array(unlist(list(matrix(runif(1000), img_width ^ 2, img_height ^ 2), matrix(runif(1000), img_width ^ 2, img_height ^ 2), 229 | 230 | matrix(runif(1000), img_width ^ 2, img_height ^ 2))), dim = c(100, 100, 3)) 231 | 232 | cls = 3 233 | ornt = 6 234 | 235 | res = HOG_apply(ARRAY1, cells = cls, orientations = ornt, threads = 1) 236 | 237 | testthat::expect_true( nrow(res) == dim(ARRAY1)[3] && cls ^ 2 * ornt == ncol(res) ) 238 | }) 239 | -------------------------------------------------------------------------------- /tests/testthat/test-laplacian_kernels.R: -------------------------------------------------------------------------------- 1 | context('Laplacian kernels') 2 | 3 | 4 | testthat::test_that("it returns a matrix", { 5 | 6 | testthat::expect_true(is.matrix(laplacian_kernels(type = 1))) 7 | }) 8 | 9 | testthat::test_that("type is a number between 1 and 4", { 10 | 11 | testthat::expect_error(laplacian_kernels(type = 5)) 12 | }) 13 | 14 | # test various kernel-types 15 | 16 | 17 | testthat::test_that("it returns a matrix", { 18 | 19 | testthat::expect_true(is.matrix(laplacian_kernels(type = 2))) 20 | }) 21 | 22 | testthat::test_that("it returns a matrix", { 23 | 24 | testthat::expect_true(is.matrix(laplacian_kernels(type = 3))) 25 | }) 26 | 27 | testthat::test_that("it returns a matrix", { 28 | 29 | testthat::expect_true(is.matrix(laplacian_kernels(type = 4))) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-list_to_array_translation.R: -------------------------------------------------------------------------------- 1 | 2 | test_mat = matrix(0, 100, 100) 3 | 4 | test_df = data.frame(matrix(0, 100, 100)) 5 | 6 | test_array = array(0, dim = c(100, 100, 3)) 7 | 8 | test_lst = list(matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10)) 9 | 10 | 11 | 12 | context("List to array and translation") 13 | 14 | ######################## 15 | # List_2_array function 16 | ######################## 17 | 18 | 19 | testthat::test_that("the function List_2_Array returns an error if the data is not a List", { 20 | 21 | testthat::expect_error( List_2_Array(test_lst[[1]]) ) 22 | }) 23 | 24 | 25 | testthat::test_that("the function List_2_Array returns an error if the sublists of the data are not matrices", { 26 | 27 | tmp_lst = list(data.frame(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 10)) 28 | 29 | testthat::expect_error( List_2_Array(tmp_lst) ) 30 | }) 31 | 32 | 33 | testthat::test_that("the function List_2_Array returns an error if the dimensions of the sublists are not equal", { 34 | 35 | tmp_lst = list(matrix(0, 100, 10), matrix(0, 10, 10), matrix(0, 10, 10), matrix(0, 10, 100), matrix(0, 10, 10), matrix(0, 10, 10)) 36 | 37 | testthat::expect_error( List_2_Array(tmp_lst) ) 38 | }) 39 | 40 | 41 | testthat::test_that("the function List_2_Array returns the correct output, if verbose is TRUE", { 42 | 43 | res = List_2_Array(test_lst, verbose = T) 44 | 45 | testthat::expect_true( inherits(res, 'array') && mean(apply(res, 3, nrow)) == mean(unlist(lapply(test_lst, nrow))) && mean(apply(res, 3, ncol)) == mean(unlist(lapply(test_lst, ncol)))) 46 | }) 47 | 48 | 49 | testthat::test_that("the function List_2_Array returns the correct output, if verbose is FALSE", { 50 | 51 | res = List_2_Array(test_lst, verbose = F) 52 | 53 | testthat::expect_true( inherits(res, 'array') && mean(apply(res, 3, nrow)) == mean(unlist(lapply(test_lst, nrow))) && mean(apply(res, 3, ncol)) == mean(unlist(lapply(test_lst, ncol)))) 54 | }) 55 | 56 | 57 | ####################### 58 | # translation function 59 | ####################### 60 | 61 | testthat::test_that("the function translation returns an error if both shift_rows and shift_cols are 0", { 62 | 63 | testthat::expect_error( translation(test_array, shift_rows = 0, shift_cols = 0) ) 64 | }) 65 | 66 | 67 | testthat::test_that("the function translation returns an error if the input image is not a matrix, data frame or array (in this case input data is a vector)", { 68 | 69 | testthat::expect_error( translation(1:10, shift_rows = 10, shift_cols = 0) ) 70 | }) 71 | 72 | 73 | testthat::test_that("the function translation returns an error if the input image is not a matrix, data frame or array (in this case input data is a list)", { 74 | 75 | testthat::expect_error( translation(list(1:10), shift_rows = 10, shift_cols = 0) ) 76 | }) 77 | 78 | 79 | testthat::test_that("the function translation returns an error if the padded_value parameter is not a numeric value (in case that the input is a matrix)", { 80 | 81 | testthat::expect_error( translation(test_mat, shift_rows = 10, shift_cols = 0, padded_value = c(0,1,1)) ) 82 | }) 83 | 84 | 85 | testthat::test_that("the function translation returns an error if the padded_value parameter is not a numeric vector of length 3 (in case that the input is an array)", { 86 | 87 | testthat::expect_error( translation(test_array, shift_rows = 10, shift_cols = 0, padded_value = c(0,1)) ) 88 | }) 89 | 90 | 91 | # matrix 92 | 93 | testthat::test_that("the function translation returns the correct output in case of matrix and shift_rows and shift_cols are positive", { 94 | 95 | res = translation(test_mat, shift_rows = 10, shift_cols = 10) 96 | 97 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_mat) && ncol(res) == ncol(test_mat) ) 98 | }) 99 | 100 | 101 | testthat::test_that("the function translation returns the correct output in case of matrix and shift_rows and shift_cols are negative", { 102 | 103 | res = translation(test_mat, shift_rows = -10, shift_cols = -10) 104 | 105 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_mat) && ncol(res) == ncol(test_mat) ) 106 | }) 107 | 108 | 109 | testthat::test_that("the function translation returns the correct output in case of matrix and shift_rows are positive and shift_cols are negative", { 110 | 111 | res = translation(test_mat, shift_rows = 10, shift_cols = -10) 112 | 113 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_mat) && ncol(res) == ncol(test_mat) ) 114 | }) 115 | 116 | 117 | testthat::test_that("the function translation returns the correct output in case of matrix and shift_rows are negative and shift_cols are positive", { 118 | 119 | res = translation(test_mat, shift_rows = -10, shift_cols = 10) 120 | 121 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_mat) && ncol(res) == ncol(test_mat) ) 122 | }) 123 | 124 | 125 | # data frame 126 | 127 | testthat::test_that("the function translation returns the correct output in case of data frame and shift_rows and shift_cols are positive", { 128 | 129 | res = translation(test_df, shift_rows = 10, shift_cols = 10) 130 | 131 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_df) && ncol(res) == ncol(test_df) ) 132 | }) 133 | 134 | 135 | testthat::test_that("the function translation returns the correct output in case of data frame and shift_rows and shift_cols are negative", { 136 | 137 | res = translation(test_df, shift_rows = -10, shift_cols = -10) 138 | 139 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_df) && ncol(res) == ncol(test_df) ) 140 | }) 141 | 142 | 143 | testthat::test_that("the function translation returns the correct output in case of data frame and shift_rows are positive and shift_cols are negative", { 144 | 145 | res = translation(test_df, shift_rows = 10, shift_cols = -10) 146 | 147 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_df) && ncol(res) == ncol(test_df) ) 148 | }) 149 | 150 | 151 | testthat::test_that("the function translation returns the correct output in case of data frame and shift_rows are negative and shift_cols are positive", { 152 | 153 | res = translation(test_df, shift_rows = -10, shift_cols = 10) 154 | 155 | testthat::expect_true( is.matrix(res) && nrow(res) == nrow(test_df) && ncol(res) == ncol(test_df) ) 156 | }) 157 | 158 | 159 | 160 | # array 161 | 162 | testthat::test_that("the function translation returns the correct output in case of array and shift_rows and shift_cols are positive", { 163 | 164 | res = translation(test_array, shift_rows = 10, shift_cols = 10) 165 | 166 | testthat::expect_true( is.array(res) && mean(apply(res, 3, nrow)) == mean(apply(test_array, 3, nrow)) && mean(apply(res, 3, ncol)) == mean(apply(test_array, 3, nrow)) ) 167 | }) 168 | 169 | 170 | testthat::test_that("the function translation returns the correct output in case of array and shift_rows and shift_cols are negative", { 171 | 172 | res = translation(test_array, shift_rows = -10, shift_cols = -10) 173 | 174 | testthat::expect_true( is.array(res) && mean(apply(res, 3, nrow)) == mean(apply(test_array, 3, nrow)) && mean(apply(res, 3, ncol)) == mean(apply(test_array, 3, nrow)) ) 175 | }) 176 | 177 | 178 | testthat::test_that("the function translation returns the correct output in case of array and shift_rows are positive and shift_cols are negative", { 179 | 180 | res = translation(test_array, shift_rows = 10, shift_cols = -10) 181 | 182 | testthat::expect_true( is.array(res) && mean(apply(res, 3, nrow)) == mean(apply(test_array, 3, nrow)) && mean(apply(res, 3, ncol)) == mean(apply(test_array, 3, nrow)) ) 183 | }) 184 | 185 | 186 | testthat::test_that("the function translation returns the correct output in case of array and shift_rows are negative and shift_cols are positive", { 187 | 188 | res = translation(test_array, shift_rows = -10, shift_cols = 10) 189 | 190 | testthat::expect_true( is.array(res) && mean(apply(res, 3, nrow)) == mean(apply(test_array, 3, nrow)) && mean(apply(res, 3, ncol)) == mean(apply(test_array, 3, nrow)) ) 191 | }) 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /tests/testthat/test-norm_matrix_range.R: -------------------------------------------------------------------------------- 1 | 2 | #--------------------------------------------------------------------------------- 3 | # data 4 | #----- 5 | 6 | set.seed(1) 7 | mt = matrix(1:48, 8, 6) 8 | MIN = -1 9 | MAX = 1 10 | 11 | MIN_ = 0 12 | MAX_ = 255 13 | 14 | #--------------------------------------------------------------------------------- 15 | # results using the interp function in numpy [ python ] 16 | #--------------------------------------------------------------------------------- 17 | 18 | # np = reticulate::import("numpy") 19 | # np$interp(mt, reticulate::tuple(min(mt), max(mt)), reticulate::tuple(MIN, MAX)) 20 | 21 | # using dput() and rounded to 8 digits 22 | 23 | np_res = structure(c(-1, -0.95744681, -0.91489362, -0.87234043, -0.82978723, 24 | -0.78723404, -0.74468085, -0.70212766, -0.65957447, -0.61702128, 25 | -0.57446809, -0.53191489, -0.4893617, -0.44680851, -0.40425532, 26 | -0.36170213, -0.31914894, -0.27659574, -0.23404255, -0.19148936, 27 | -0.14893617, -0.10638298, -0.06382979, -0.0212766, 0.0212766, 28 | 0.06382979, 0.10638298, 0.14893617, 0.19148936, 0.23404255, 0.27659574, 29 | 0.31914894, 0.36170213, 0.40425532, 0.44680851, 0.4893617, 0.53191489, 30 | 0.57446809, 0.61702128, 0.65957447, 0.70212766, 0.74468085, 0.78723404, 31 | 0.82978723, 0.87234043, 0.91489362, 0.95744681, 1), .Dim = c(8L, 6L)) 32 | 33 | np_res_255 = structure(c(0, 5.42553191, 10.85106383, 16.27659574, 21.70212766, 34 | 27.12765957, 32.55319149, 37.9787234, 43.40425532, 48.82978723, 35 | 54.25531915, 59.68085106, 65.10638298, 70.53191489, 75.95744681, 36 | 81.38297872, 86.80851064, 92.23404255, 97.65957447, 103.08510638, 37 | 108.5106383, 113.93617021, 119.36170213, 124.78723404, 130.21276596, 38 | 135.63829787, 141.06382979, 146.4893617, 151.91489362, 157.34042553, 39 | 162.76595745, 168.19148936, 173.61702128, 179.04255319, 184.46808511, 40 | 189.89361702, 195.31914894, 200.74468085, 206.17021277, 211.59574468, 41 | 217.0212766, 222.44680851, 227.87234043, 233.29787234, 238.72340426, 42 | 244.14893617, 249.57446809, 255), .Dim = c(8L, 6L)) 43 | 44 | #--------------------------------------------------------------------------------- 45 | 46 | 47 | context('Output of data normalized in specific range') 48 | 49 | 50 | testthat::test_that("it returns an error if the data is not a matrix", { 51 | 52 | testthat::expect_error(norm_matrix_range(list(mt), min_value = MIN, max_value = MAX)) 53 | }) 54 | 55 | 56 | if (!((as.character(Sys.info()["sysname"]) == 'Darwin') & (version$arch == 'powerpc'))) { # add an exception for Power-PC Mac OSx (see: https://github.com/mlampros/OpenImageR/issues/27) 57 | 58 | testthat::test_that("the 'norm_matrix_range' returns the correct output ( range = c(-1,1) )", { 59 | 60 | # rounded to 8 digits as in np$interp() 61 | res = round(norm_matrix_range(mt, min_value = MIN, max_value = MAX), 8) 62 | 63 | testthat::expect_true(identical(res, np_res)) 64 | }) 65 | 66 | 67 | testthat::test_that("the 'norm_matrix_range' returns the correct output ( range = c(0,255) )", { 68 | 69 | # rounded to 8 digits as in np$interp() 70 | res = round(norm_matrix_range(mt, min_value = MIN_, max_value = MAX_), 8) 71 | 72 | testthat::expect_true(identical(res, np_res_255)) 73 | }) 74 | } 75 | -------------------------------------------------------------------------------- /tests/testthat/test-normalize_min_max.R: -------------------------------------------------------------------------------- 1 | 2 | object_mat = matrix(runif(10000), 100, 100) # a matrix 3 | 4 | object_array = array(runif(30000), dim = c(100, 100, 3)) # an array 5 | 6 | object_list = list(array(runif(30000), dim = c(100, 100, 3)), array(runif(30000), dim = c(100, 100, 3)), 7 | 8 | array(runif(30000), dim = c(100, 100, 3)), array(runif(30000), dim = c(100, 100, 3))) # a list of 3-dimensional arrays 9 | 10 | 11 | context('NormalizeObject and MinMaxObject') 12 | 13 | 14 | 15 | # NormalizeObject 16 | 17 | 18 | testthat::test_that("it returns an error if the object is not a vector, data frame, matrix or array", { 19 | 20 | testthat::expect_error( NormalizeObject(object_list) ) 21 | }) 22 | 23 | 24 | testthat::test_that("in case of a vector it returns the same class object in range of values between 0 and 1", { 25 | 26 | res = NormalizeObject(1:10) 27 | 28 | testthat::expect_true( min(res) == 0.0 && max(res) == 1.0 && is.vector(res) && length(res) == length(1:10) ) 29 | }) 30 | 31 | 32 | testthat::test_that("in case of a data frame it returns a matrix in range of values between 0 and 1", { 33 | 34 | res = NormalizeObject(data.frame(object_mat)) 35 | 36 | testthat::expect_true( min(res) == 0.0 && max(res) == 1.0 && is.matrix(res) && nrow(res) == nrow(object_mat) && ncol(res) == ncol(object_mat) ) 37 | }) 38 | 39 | 40 | testthat::test_that("in case of a matrix it returns a matrix in range of values between 0 and 1", { 41 | 42 | res = NormalizeObject(object_mat) 43 | 44 | testthat::expect_true( min(res) == 0.0 && max(res) == 1.0 && is.matrix(res) && nrow(res) == nrow(object_mat) && ncol(res) == ncol(object_mat) ) 45 | }) 46 | 47 | 48 | 49 | testthat::test_that("in case of an array it returns an array in range of values between 0 and 1", { 50 | 51 | res = NormalizeObject(object_array) 52 | 53 | testthat::expect_true( min(res) == 0.0 && max(res) == 1.0 && is.array(res) && nrow(res) == nrow(object_mat) && ncol(res) == ncol(object_mat) && dim(res)[3] == 3) 54 | }) 55 | 56 | 57 | 58 | # MinMaxObject 59 | 60 | 61 | testthat::test_that("it returns an error if the object is not a vector, data frame, matrix or array", { 62 | 63 | testthat::expect_error( MinMaxObject(object_list) ) 64 | }) 65 | 66 | 67 | testthat::test_that("in case of a vector it returns the same class object in range of values between 0 and 1", { 68 | 69 | res = MinMaxObject(1:10) 70 | 71 | testthat::expect_true( is.list(res) && length(res) == 2 && res$min == min(1:10) && res$max == max(1:10) ) 72 | }) 73 | 74 | 75 | testthat::test_that("in case of a data frame it returns a matrix in range of values between 0 and 1", { 76 | 77 | res = MinMaxObject(data.frame(object_mat)) 78 | 79 | testthat::expect_true( is.list(res) && length(res) == 2 && res$min == min(object_mat) && res$max == max(object_mat) ) 80 | }) 81 | 82 | 83 | testthat::test_that("in case of a matrix it returns a matrix in range of values between 0 and 1", { 84 | 85 | res = MinMaxObject(object_mat) 86 | 87 | testthat::expect_true( is.list(res) && length(res) == 2 && res$min == min(object_mat) && res$max == max(object_mat) ) 88 | }) 89 | 90 | 91 | testthat::test_that("in case of an array it returns an array in range of values between 0 and 1", { 92 | 93 | res = MinMaxObject(object_array) 94 | 95 | testthat::expect_true( is.list(res) && length(res) == 2 && mean(unlist(lapply(res, length))) == dim(object_array)[3] && min(res$min) == min(apply(object_array, 3, min)) && max(res$max) == max(apply(object_array, 3, max))) 96 | }) 97 | -------------------------------------------------------------------------------- /tests/testthat/test-read_image.R: -------------------------------------------------------------------------------- 1 | context('Test reading images') 2 | 3 | 4 | testthat::test_that("the 'verify_image_extension' function gives an error if there is no file extension in the input image", { 5 | 6 | example_img_path = 'example_img' 7 | 8 | testthat::expect_error( verify_image_extension(image_path = example_img_path) ) 9 | }) 10 | 11 | 12 | testthat::test_that("the 'verify_image_extension' function returns only supported from the OpenImageR package file extensions", { 13 | 14 | vec_img_ext = c('png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'tif', 'TIF', 'tiff', 'TIFF') 15 | 16 | vec_valid = sapply(vec_img_ext, function(x) { 17 | ext_iter = paste(c('example_image', x), collapse = '.') 18 | verify_image_extension(image_path = ext_iter) 19 | }) 20 | 21 | testthat::expect_true( all(vec_img_ext == vec_valid) ) 22 | }) 23 | 24 | 25 | testthat::test_that("if the input is a not a valid path it returns an error", { 26 | 27 | testthat::expect_error( readImage(5) ) 28 | }) 29 | 30 | 31 | testthat::test_that("if the input is a not a valid path it returns an error", { 32 | 33 | testthat::expect_error( readImage('/home/lampros') ) 34 | }) 35 | 36 | 37 | testthat::test_that("if the input is a .png it retruns a 3-dimensional array", { 38 | 39 | Folder = paste0(getwd(), path.expand("/image_files/")) 40 | 41 | lst_files = list.files(Folder) 42 | 43 | path = lst_files[1] 44 | 45 | res = readImage( paste0(Folder, path) ) 46 | 47 | testthat::expect_true( is.array(res) && length(dim(res)) == 3 && sum(dim(res)) > 0) 48 | }) 49 | 50 | 51 | 52 | testthat::test_that("if the input is a .jpg it retruns a 3-dimensional array", { 53 | 54 | Folder = paste0(getwd(), path.expand("/image_files/")) 55 | 56 | lst_files = list.files(Folder) 57 | 58 | path = lst_files[2] 59 | 60 | res = readImage( paste0(Folder, path) ) 61 | 62 | testthat::expect_true( is.array(res) && length(dim(res)) == 3 && sum(dim(res)) > 0) 63 | }) 64 | 65 | 66 | testthat::test_that("if the input is a .jpeg it retruns a 3-dimensional array", { 67 | 68 | Folder = paste0(getwd(), path.expand("/image_files/")) 69 | 70 | lst_files = list.files(Folder) 71 | 72 | path = lst_files[3] 73 | 74 | res = readImage( paste0(Folder, path) ) 75 | 76 | testthat::expect_true( is.array(res) && length(dim(res)) == 3 && sum(dim(res)) > 0) 77 | }) 78 | 79 | 80 | 81 | testthat::test_that("if the input is a .tiff it retruns a matrix", { 82 | 83 | Folder = paste0(getwd(), path.expand("/image_files/")) 84 | 85 | lst_files = list.files(Folder) 86 | 87 | path = lst_files[4] 88 | 89 | res = readImage( paste0(Folder, path) ) 90 | 91 | testthat::expect_true( is.matrix(res) && length(dim(res)) == 2 && sum(dim(res)) > 0) 92 | }) 93 | 94 | -------------------------------------------------------------------------------- /tests/testthat/test-resize_nearest.R: -------------------------------------------------------------------------------- 1 | context("Resize image") 2 | 3 | 4 | testthat::test_that("in case that the method is not valid it returns an error", { 5 | 6 | height = width = 15 7 | 8 | image_array = matrix(runif(100), 10, 10) 9 | 10 | testthat::expect_error(resizeImage(image_array, width, height, method = 'invalid')) 11 | }) 12 | 13 | 14 | testthat::test_that("in case of a data frame the resizeImage function returns a matrix with dimensions equal to the height, width", { 15 | 16 | height = width = 15 17 | 18 | image_array = as.data.frame(matrix(runif(100), 10, 10)) 19 | 20 | matr = resizeImage(image_array, width, height) 21 | 22 | testthat::expect_true(is.matrix(matr) && nrow(matr) == width && ncol(matr) == width) 23 | }) 24 | 25 | 26 | testthat::test_that("in case of a matrix the resizeImage function returns a matrix with dimensions equal to the height, width", { 27 | 28 | height = width = 15 29 | 30 | image_array = matrix(runif(100), 10, 10) 31 | 32 | matr = resizeImage(image_array, width, height, method = 'nearest') 33 | 34 | testthat::expect_true(is.matrix(matr) && nrow(matr) == width && ncol(matr) == width) 35 | }) 36 | 37 | 38 | testthat::test_that("in case of an array the resizeImage function returns an array with rows and cols of each array equal to the height, width", { 39 | 40 | height = width = 15 41 | 42 | image_array = array(unlist(list(matrix(runif(100), 10, 10), matrix(runif(100), 10, 10), matrix(runif(100), 10, 10))), dim = c(10, 10, 3)) 43 | 44 | matr = resizeImage(image_array, width, height, method = 'nearest') 45 | 46 | testthat::expect_true(is.array(matr) && mean(apply(matr, 3, nrow)) == width && mean(apply(matr, 3, ncol)) == width) 47 | }) 48 | 49 | 50 | testthat::test_that("in case of a matrix the resizeImage function returns a matrix with dimensions equal to the height, width", { 51 | 52 | height = width = 15 53 | 54 | image_array = matrix(runif(100), 10, 10) 55 | 56 | matr = resizeImage(image_array, width, height, method = 'bilinear') 57 | 58 | testthat::expect_true(is.matrix(matr) && nrow(matr) == width && ncol(matr) == width) 59 | }) 60 | 61 | 62 | testthat::test_that("in case of an array the resizeImage function returns an array with rows and cols of each array equal to the height, width", { 63 | 64 | height = width = 15 65 | 66 | image_array = array(unlist(list(matrix(runif(100), 10, 10), matrix(runif(100), 10, 10), matrix(runif(100), 10, 10))), dim = c(10, 10, 3)) 67 | 68 | matr = resizeImage(image_array, width, height, method = 'bilinear') 69 | 70 | testthat::expect_true(is.array(matr) && mean(apply(matr, 3, nrow)) == width && mean(apply(matr, 3, ncol)) == width) 71 | }) 72 | 73 | 74 | testthat::test_that("in case of an invalid type of image the function returns an error", { 75 | 76 | height = width = 15 77 | 78 | image_array = list(matrix(runif(25), 5, 5)) 79 | 80 | testthat::expect_error(resizeImage(image_array, width, height)) 81 | }) 82 | 83 | 84 | testthat::test_that("in case of width less than 1.0 the function returns an error", { 85 | 86 | height = 20 87 | width = 0.5 88 | 89 | image_array = as.data.frame(matrix(runif(100), 10, 10)) 90 | 91 | testthat::expect_error(resizeImage(image_array, width, height)) 92 | }) 93 | 94 | 95 | testthat::test_that("in case of height less than 1.0 the function returns an error", { 96 | 97 | height = 0.5 98 | width = 20 99 | 100 | image_array = as.data.frame(matrix(runif(100), 10, 10)) 101 | 102 | testthat::expect_error(resizeImage(image_array, width, height)) 103 | }) 104 | 105 | 106 | 107 | testthat::test_that("the resizeImage() function gives multiple warnings in case of a 3-band image and method 'nearest'", { 108 | 109 | ROWS = 644 # for the dimensions that give the warning see the following issue: https://github.com/mlampros/OpenImageR/issues/21 110 | COLS = 969 111 | BANDS = 3 112 | resize_w_h = 8 113 | 114 | image_array = array(runif(ROWS * COLS * BANDS), dim = c(ROWS, COLS, BANDS)) 115 | 116 | testthat::expect_warning(resizeImage(image = image_array, width = resize_w_h, height = resize_w_h, method = 'nearest')) 117 | }) 118 | 119 | 120 | testthat::test_that("the resizeImage() function gives warnings in case of a single-band image and method 'nearest", { 121 | 122 | ROWS = 644 # for the dimensions that give the warning see the following issue: https://github.com/mlampros/OpenImageR/issues/21 123 | COLS = 969 124 | resize_w_h = 8 125 | 126 | image_matrix = matrix(runif(ROWS * COLS), nrow = ROWS, ncol = COLS) 127 | 128 | testthat::expect_warning(resizeImage(image_matrix, width = resize_w_h, height = resize_w_h, method = 'nearest')) 129 | }) 130 | 131 | -------------------------------------------------------------------------------- /tests/testthat/test-rgb_to_gray.R: -------------------------------------------------------------------------------- 1 | context('Convert RGB image to gray') 2 | 3 | 4 | testthat::test_that("it returns an error if the image is not 3-dimensional", { 5 | 6 | out_array = matrix(1:100, 10, 10) 7 | 8 | testthat::expect_error(rgb_2gray(out_array)) 9 | }) 10 | 11 | 12 | testthat::test_that("the function takes a 3-dimensional array and it returns a 2-dimensional matrix", { 13 | 14 | out_array = array(runif(300), dim = c(10, 10, 3)) 15 | 16 | res = rgb_2gray(out_array) 17 | 18 | testthat::expect_true(is.matrix(res) && nrow(res) == dim(out_array)[1] && ncol(res) == dim(out_array)[2]) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-rotate.R: -------------------------------------------------------------------------------- 1 | context('Rotate image') 2 | 3 | 4 | # rotateFixed function [ rotates an image for 90, 180, 270 degrees ] 5 | 6 | 7 | testthat::test_that("in case that image is not an array, matrix or data frame it returns an error", { 8 | 9 | image_array = list(image_array = matrix(runif(25), 5, 5)) 10 | 11 | testthat::expect_error( rotateFixed(image_array, angle = 90) ) 12 | }) 13 | 14 | testthat::test_that("in case that the angle is not 90, 180, 270 it returns an error", { 15 | 16 | image_array = matrix(runif(25), 5, 5) 17 | 18 | testthat::expect_error( rotateFixed(image_array, angle = 100) ) 19 | }) 20 | 21 | 22 | # test different angles [ for matrix/data.frame ] 23 | 24 | testthat::test_that("in case of an angle it returns a matrix", { 25 | 26 | image_array = matrix(runif(25), 5, 5) 27 | 28 | testthat::expect_true(is.matrix(rotateFixed(image_array, angle = 90))) 29 | }) 30 | 31 | testthat::test_that("in case of an angle it returns a matrix", { 32 | 33 | image_array = matrix(runif(25), 5, 5) 34 | 35 | testthat::expect_true(is.matrix(rotateFixed(image_array, angle = 180))) 36 | }) 37 | 38 | 39 | testthat::test_that("in case of an angle it returns a matrix", { 40 | 41 | image_array = data.frame(matrix(runif(25), 5, 5)) 42 | 43 | testthat::expect_true(is.matrix(rotateFixed(image_array, angle = 270))) 44 | }) 45 | 46 | 47 | # test different angles [ for array ] 48 | 49 | testthat::test_that("in case of an angle it returns a array", { 50 | 51 | image_array = array(runif(300), dim = c(10,10,3)) 52 | 53 | testthat::expect_true(is.array(rotateFixed(image_array, angle = 90))) 54 | }) 55 | 56 | testthat::test_that("in case of an angle it returns a array", { 57 | 58 | image_array = array(runif(300), dim = c(10,10,3)) 59 | 60 | testthat::expect_true(is.array(rotateFixed(image_array, angle = 180))) 61 | }) 62 | 63 | 64 | testthat::test_that("in case of an angle it returns a array", { 65 | 66 | image_array = array(runif(300), dim = c(10,10,3)) 67 | 68 | testthat::expect_true(is.array(rotateFixed(image_array, angle = 270))) 69 | }) 70 | 71 | 72 | # rotateImage function [ rotate image in a range between 0.0 and 360.0 degrees ] 73 | 74 | 75 | testthat::test_that("in case of a gray image (2-dimensional) when the angle value is below 0.0 degrees it returns an error", { 76 | 77 | image_array = matrix(runif(25), 5, 5) 78 | 79 | testthat::expect_error( rotateImage(image_array, -1, threads = 1) ) 80 | }) 81 | 82 | 83 | testthat::test_that("in case of a gray image (2-dimensional) when the angle value is greater than 360.0 degrees it returns an error", { 84 | 85 | image_array = matrix(runif(25), 5, 5) 86 | 87 | testthat::expect_error( rotateImage(image_array, 360.5, threads = 1) ) 88 | }) 89 | 90 | 91 | testthat::test_that("in case of a gray image (2-dimensional) if the input image is invalid it returns an error", { 92 | 93 | image_array = list(matrix(runif(25), 5, 5)) 94 | 95 | testthat::expect_error( rotateImage(image_array, 60, threads = 1) ) 96 | }) 97 | 98 | 99 | testthat::test_that("in case of a gray image (2-dimensional) if the number of threads is less than 1 it returns an error", { 100 | 101 | image_array = matrix(runif(25), 5, 5) 102 | 103 | testthat::expect_error( rotateImage(image_array, 60, threads = 0) ) 104 | }) 105 | 106 | 107 | testthat::test_that("in case of a gray image (2-dimensional) if the method is invalid it returns an error", { 108 | 109 | image_array = matrix(runif(25), 5, 5) 110 | 111 | testthat::expect_error( rotateImage(image_array, 60, method = 'invalid', threads = 1) ) 112 | }) 113 | 114 | 115 | testthat::test_that("in case of a gray image (2-dimensional) if the mode is invalid it returns an error", { 116 | 117 | image_array = matrix(runif(25), 5, 5) 118 | 119 | testthat::expect_error( rotateImage(image_array, 60, mode = 'invalid', threads = 1) ) 120 | }) 121 | 122 | testthat::test_that("in case of a gray image (2-dimensional) if the mode is invalid it returns an error", { 123 | 124 | image_array = array(runif(300), dim = c(10,10,3)) 125 | 126 | testthat::expect_error( rotateImage(image_array, 60, mode = 'invalid', threads = 1) ) 127 | }) 128 | 129 | testthat::test_that("in case of a gray image (2-dimensional) it returns a matrix with the same dimensions of the initial image, 20 degrees", { 130 | 131 | image_array = matrix(runif(25), 5, 5) 132 | 133 | res = rotateImage(image_array, 20, method = 'nearest', mode = 'full', threads = 1) 134 | 135 | testthat::expect_true(is.matrix(res) && nrow(res) != nrow(image_array) && ncol(res) != ncol(image_array)) 136 | }) 137 | 138 | testthat::test_that("in case of a gray image (2-dimensional) it returns a matrix with the same dimensions of the initial image, 20 degrees", { 139 | 140 | image_array = matrix(runif(25), 5, 5) 141 | 142 | res = rotateImage(image_array, 20, method = 'nearest', mode = 'same', threads = 1) 143 | 144 | testthat::expect_true(is.matrix(res) && nrow(res) == nrow(image_array) && ncol(res) == ncol(image_array)) 145 | }) 146 | 147 | 148 | testthat::test_that("in case of a gray image (2-dimensional) it returns a matrix with the same dimensions of the initial image, 20 degrees", { 149 | 150 | image_array = matrix(runif(25), 5, 5) 151 | 152 | res = rotateImage(image_array, 20, method = 'bilinear', mode = 'full', threads = 1) 153 | 154 | testthat::expect_true(is.matrix(res) && nrow(res) != nrow(image_array) && ncol(res) != ncol(image_array)) 155 | }) 156 | 157 | testthat::test_that("in case of a gray image (2-dimensional) it returns a matrix with the same dimensions of the initial image, 20 degrees", { 158 | 159 | image_array = matrix(runif(25), 5, 5) 160 | 161 | res = rotateImage(image_array, 20, method = 'bilinear', mode = 'same', threads = 1) 162 | 163 | testthat::expect_true(is.matrix(res) && nrow(res) == nrow(image_array) && ncol(res) == ncol(image_array)) 164 | }) 165 | 166 | testthat::test_that("in case of a gray image (2-dimensional) it returns a matrix with the same dimensions of the initial image, 90 degrees", { 167 | 168 | image_array = matrix(runif(25), 5, 5) 169 | 170 | res = rotateImage(image_array, 90, threads = 1) 171 | 172 | testthat::expect_true(is.matrix(res) && nrow(res) == nrow(image_array) && ncol(res) == ncol(image_array)) 173 | }) 174 | 175 | 176 | testthat::test_that("in case of an RGB image (3-dimensional) it returns a 3-dimensional array", { 177 | 178 | image_array = array(runif(300), dim = c(10,10,3)) 179 | 180 | res = rotateImage(image_array, 20, method = 'nearest', mode = 'same', threads = 1) 181 | 182 | testthat::expect_true(is.array(res) && dim(res)[1] == dim(image_array)[1] && dim(res)[2] == dim(image_array)[2] && dim(res)[3] == dim(image_array)[3]) 183 | }) 184 | 185 | testthat::test_that("in case of an RGB image (3-dimensional) it returns a 3-dimensional array", { 186 | 187 | image_array = array(runif(300), dim = c(10,10,3)) 188 | 189 | res = rotateImage(image_array, 20, method = 'nearest', mode = 'full', threads = 1) 190 | 191 | testthat::expect_true(is.array(res) && dim(res)[1] != dim(image_array)[1] && dim(res)[2] != dim(image_array)[2] && dim(res)[3] == dim(image_array)[3]) 192 | }) 193 | 194 | testthat::test_that("in case of an RGB image (3-dimensional) it returns a 3-dimensional array", { 195 | 196 | image_array = array(runif(300), dim = c(10,10,3)) 197 | 198 | res = rotateImage(image_array, 20, method = 'bilinear', mode = 'same', threads = 1) 199 | 200 | testthat::expect_true(is.array(res) && dim(res)[1] == dim(image_array)[1] && dim(res)[2] == dim(image_array)[2] && dim(res)[3] == dim(image_array)[3]) 201 | }) 202 | 203 | testthat::test_that("in case of an RGB image (3-dimensional) it returns a 3-dimensional array", { 204 | 205 | image_array = array(runif(300), dim = c(10,10,3)) 206 | 207 | res = rotateImage(image_array, 20, method = 'bilinear', mode = 'full', threads = 1) 208 | 209 | testthat::expect_true(is.array(res) && dim(res)[1] != dim(image_array)[1] && dim(res)[2] != dim(image_array)[2] && dim(res)[3] == dim(image_array)[3]) 210 | }) 211 | -------------------------------------------------------------------------------- /tests/testthat/test-shiny_apps.R: -------------------------------------------------------------------------------- 1 | context("Shiny apps") 2 | 3 | # here I use the try catch function 4 | testthat::test_that("in case that the file_path argument of the image_show function is not an array, matrix or path then it returns an error", { 5 | 6 | image_array = list(image_array = matrix(runif(25), 5, 5)) 7 | 8 | testthat::expect_error(imageShow(image_array)) 9 | }) 10 | 11 | -------------------------------------------------------------------------------- /tests/testthat/test-uniform_filter_convolution.R: -------------------------------------------------------------------------------- 1 | context('Uniform filter convolution') 2 | 3 | 4 | # uniform filter 5 | 6 | testthat::test_that("in case of an array input (image) the uniform_filter function returns an array", { 7 | 8 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 9 | 10 | testthat::expect_true(is.array(uniform_filter(image_array, c(3,3), conv_mode = 'same'))) 11 | }) 12 | 13 | testthat::test_that("in case of a matrix input (image) the uniform_filter function returns a matrix", { 14 | 15 | image_array = matrix(runif(25), 5, 5) 16 | 17 | testthat::expect_true(is.matrix(uniform_filter(image_array, c(3,3), conv_mode = 'full'))) 18 | }) 19 | 20 | testthat::test_that("in case of a another type of image returns an error", { 21 | 22 | image_array = list(matrix(runif(25), 5, 5)) 23 | 24 | testthat::expect_error(uniform_filter(image_array, c(3,3), conv_mode = 'same')) 25 | }) 26 | 27 | testthat::test_that("in case that the 'size' argument is not a vector it returns an error", { 28 | 29 | image_array = matrix(runif(25), 5, 5) 30 | 31 | testthat::expect_error(uniform_filter(image_array, NULL, conv_mode = 'same')) 32 | }) 33 | 34 | testthat::test_that("in case that the 'conv_mode' argument is NULL it returns an error", { 35 | 36 | image_array = matrix(runif(25), 5, 5) 37 | 38 | testthat::expect_error(uniform_filter(image_array, c(3,3), conv_mode = NULL)) 39 | }) 40 | 41 | 42 | testthat::test_that("in case that the 'conv_mode' argument is not one of 'same', 'full' it returns an error", { 43 | 44 | image_array = matrix(runif(25), 5, 5) 45 | 46 | testthat::expect_error(uniform_filter(image_array, c(3,3), conv_mode = 'invalid')) 47 | }) 48 | 49 | 50 | 51 | # convolution 52 | 53 | 54 | testthat::test_that("if image is not a data frame, matrix or array it returns an error", { 55 | 56 | image_array = list(matrix(runif(25), 5, 5)) 57 | 58 | kern = matrix(1, 4, 4) / 16 59 | 60 | testthat::expect_error( convolution(image_array, kern, mode = "same") ) 61 | }) 62 | 63 | 64 | testthat::test_that("if mode is not one of same, full it returns an error", { 65 | 66 | image_array = matrix(runif(25), 5, 5) 67 | 68 | kern = matrix(1, 4, 4) / 16 69 | 70 | testthat::expect_error( convolution(image_array, kern, mode = "invalid") ) 71 | }) 72 | 73 | 74 | testthat::test_that("if the kernel is not a matrix it returns an error", { 75 | 76 | image_array = matrix(runif(25), 5, 5) 77 | 78 | kern = as.vector(matrix(1, 4, 4) / 16) 79 | 80 | testthat::expect_error( convolution(image_array, kern, mode = "same") ) 81 | }) 82 | 83 | 84 | testthat::test_that("in case of a matrix as input it returns a correct output", { 85 | 86 | image_array = matrix(runif(25), 5, 5) 87 | 88 | kern = matrix(1, 4, 4) / 16 89 | 90 | res = convolution(image_array, kern, mode = "same") 91 | 92 | testthat::expect_true( inherits(res, 'matrix') && nrow(image_array) == nrow(res) && ncol(image_array) == ncol(res) ) 93 | }) 94 | 95 | 96 | testthat::test_that("in case of an array as input it returns a correct output", { 97 | 98 | image_array = array(unlist(list(matrix(runif(25), 5, 5), matrix(runif(25), 5, 5), matrix(runif(25), 5, 5))), dim = c(5, 5, 3)) 99 | 100 | kern = matrix(1, 4, 4) / 16 101 | 102 | res = convolution(image_array, kern, mode = "same") 103 | 104 | testthat::expect_true( inherits(res, 'array') && nrow(image_array) == nrow(res) && ncol(image_array) == ncol(res) && !is.na(dim(res)[3]) ) 105 | }) 106 | 107 | 108 | -------------------------------------------------------------------------------- /tests/testthat/test-warp_affine.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | context("Warp Affine") 4 | 5 | 6 | # Affine transformation function 7 | 8 | testthat::test_that("the 'getAffineTransform' function gives an error if the number of rows and columns of the input matrices are not the same", { 9 | 10 | r = 600 11 | c = 600 12 | offset = 50 13 | 14 | original_points = matrix(data = c(0, 0, r, 0, 0, c, 0, 0), 15 | nrow = 4, 16 | ncol = 2, 17 | byrow = TRUE) 18 | 19 | transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 20 | nrow = 3, 21 | ncol = 2, 22 | byrow = TRUE) 23 | 24 | testthat::expect_error( getAffineTransform(original_points = original_points, 25 | transformed_points = transformed_points) ) 26 | }) 27 | 28 | 29 | testthat::test_that("the output matrix has the same dimensions as the input matrices", { 30 | 31 | r = 600 32 | c = 600 33 | offset = 50 34 | 35 | original_points = matrix(data = c(0, 0, r, 0, 0, c), 36 | nrow = 3, 37 | ncol = 2, 38 | byrow = TRUE) 39 | 40 | transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 41 | nrow = 3, 42 | ncol = 2, 43 | byrow = TRUE) 44 | 45 | M_aff = getAffineTransform(original_points = original_points, 46 | transformed_points = transformed_points) 47 | 48 | testthat::expect_true( all(dim(M_aff) == rev(dim(original_points))) & all(dim(M_aff) == rev(dim(transformed_points))) ) 49 | }) 50 | 51 | 52 | # Warp Affine function 53 | 54 | 55 | testthat::test_that("the warp affine function works for 2- and 3-dimensional data", { 56 | 57 | path = file.path(getwd(), 'image_files', '3.jpeg') 58 | img = readImage(path) 59 | img = img * 255 60 | 61 | r = ncol(img) 62 | c = nrow(img) 63 | offset = 10 64 | 65 | original_points = matrix(data = c(0, 0, r, 0, 0, c), 66 | nrow = 3, 67 | ncol = 2, 68 | byrow = TRUE) 69 | 70 | transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 71 | nrow = 3, 72 | ncol = 2, 73 | byrow = TRUE) 74 | 75 | M_aff = getAffineTransform(original_points = original_points, 76 | transformed_points = transformed_points) 77 | 78 | #.............. 79 | # 2-dimensional 80 | #.............. 81 | 82 | img_2d = rgb_2gray(img) 83 | 84 | res_2d = warpAffine(img = img_2d, 85 | M = M_aff, 86 | R = r, 87 | C = c, 88 | threads = 1, 89 | verbose = FALSE) 90 | #.............. 91 | # 3-dimensional 92 | #.............. 93 | 94 | res_3d = warpAffine(img = img, 95 | M = M_aff, 96 | R = r, 97 | C = c, 98 | verbose = FALSE) 99 | 100 | testthat::expect_true( all(dim(res_2d) == c(32, 32)) & all(dim(res_3d) == c(32, 32, 3)) ) 101 | }) 102 | 103 | -------------------------------------------------------------------------------- /tests/testthat/test-write_image.R: -------------------------------------------------------------------------------- 1 | context('Test writing images') 2 | 3 | 4 | testthat::test_that("if the file_name is not a valid path it returns an error", { 5 | 6 | x = matrix(100, 10, 10) 7 | 8 | testthat::expect_error( writeImage(x, 5) ) 9 | }) 10 | 11 | 12 | testthat::test_that("if the input is not a valid path it returns an error", { 13 | 14 | x = list(matrix(100, 10, 10)) 15 | 16 | testthat::expect_error( writeImage(x, 'file.png') ) 17 | }) 18 | 19 | 20 | testthat::test_that("if the file_name is not a valid path it returns an error", { 21 | 22 | x = matrix(100, 10, 10) 23 | 24 | testthat::expect_error( writeImage(x, '/home/my_image') ) 25 | }) 26 | 27 | 28 | testthat::test_that("writeImage saves a .png successfully", { 29 | 30 | x = matrix(100, 10, 10) 31 | 32 | sav = writeImage(x, 'SAV_DEL.png') 33 | 34 | file.remove('SAV_DEL.png') 35 | 36 | testthat::expect_silent( sav ) 37 | }) 38 | 39 | 40 | testthat::test_that("writeImage saves a .png successfully, in case of data frame", { 41 | 42 | x = data.frame(matrix(100, 10, 10)) 43 | 44 | sav = writeImage(x, 'SAV_DEL.png') 45 | 46 | file.remove('SAV_DEL.png') 47 | 48 | testthat::expect_silent( sav ) 49 | }) 50 | 51 | 52 | testthat::test_that("writeImage saves a .jpg successfully", { 53 | 54 | x = matrix(100, 10, 10) 55 | 56 | sav = writeImage(x, 'SAV_DEL.jpg') 57 | 58 | file.remove('SAV_DEL.jpg') 59 | 60 | testthat::expect_silent( sav ) 61 | }) 62 | 63 | 64 | testthat::test_that("writeImage saves a .jpeg successfully", { 65 | 66 | x = array(runif(300), dim = c(10, 10, 3)) 67 | 68 | sav = writeImage(x, 'SAV_DEL.jpeg') 69 | 70 | file.remove('SAV_DEL.jpeg') 71 | 72 | testthat::expect_silent( sav ) 73 | }) 74 | 75 | 76 | testthat::test_that("writeImage saves a .tiff successfully", { 77 | 78 | x = matrix(100, 10, 10) 79 | 80 | sav = writeImage(x, 'SAV_DEL.tiff') 81 | 82 | file.remove('SAV_DEL.tiff') 83 | 84 | testthat::expect_silent( sav ) 85 | }) 86 | -------------------------------------------------------------------------------- /tic.R: -------------------------------------------------------------------------------- 1 | # installs dependencies, runs R CMD check, runs covr::codecov() 2 | do_package_checks() 3 | 4 | if (ci_on_ghactions() && ci_has_env("BUILD_PKGDOWN")) { 5 | # creates pkgdown site and pushes to gh-pages branch 6 | # only for the runner with the "BUILD_PKGDOWN" env var set 7 | do_pkgdown() 8 | } 9 | -------------------------------------------------------------------------------- /vignettes/TEST_hash/2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/2_1.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/2_2.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/2_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/2_3.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/4_1.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/4_2.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/4_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/4_3.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/5_1.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/5_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/5_2.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/5_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/5_3.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/8_1.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/8_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/8_2.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/8_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/8_3.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/9_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/9_1.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/9_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/9_2.png -------------------------------------------------------------------------------- /vignettes/TEST_hash/9_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/TEST_hash/9_3.png -------------------------------------------------------------------------------- /vignettes/Warp_Affine.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Warp Affine using R" 3 | author: "Lampros Mouselimis" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Warp Affine using R} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | 13 | The **getAffineTransform()** and **warpAffine()** functions of the OpenImageR package is an RcppArmadillo re-implementation of [existing Python Code](https://github.com/OlehOnyshchak/ImageTransformations/blob/master/AffineTransformation.ipynb) and this vignette shows how these functions can be used from within R based on the [author's .ipynb](https://github.com/OlehOnyshchak/ImageTransformations/blob/master/AffineTransformation.ipynb) file 14 | 15 |
16 | 17 | ```{r, eval = T} 18 | 19 | require(OpenImageR) 20 | 21 | path = system.file('tmp_images', 'landscape.jpg', package = "OpenImageR") 22 | 23 | img = readImage(path) 24 | print(dim(img)) 25 | 26 | ``` 27 | 28 |
29 | 30 | ```{r, out.width = "65%", out.height = "50%", fig.align = 'center', fig.cap = "Input Image", fig.alt="Input Image", echo = F, eval = T} 31 | 32 | knitr::include_graphics(path) 33 | 34 | ``` 35 | 36 |
37 | 38 | ```{r, eval = T} 39 | 40 | r = ncol(img) 41 | c = nrow(img) 42 | offset = 50 43 | 44 | original_points = matrix(data = c(0, 0, r, 0, 0, c), 45 | nrow = 3, 46 | ncol = 2, 47 | byrow = TRUE) 48 | 49 | transformed_points = matrix(data = c(offset, 0, r, offset, 0, c-offset), 50 | nrow = 3, 51 | ncol = 2, 52 | byrow = TRUE) 53 | 54 | M_aff = getAffineTransform(original_points = original_points, 55 | transformed_points = transformed_points) 56 | 57 | ``` 58 | 59 |
60 | 61 | The following is the Affine transformation matrix, 62 | 63 | ```{r, eval = T} 64 | 65 | print(M_aff) 66 | 67 | ``` 68 | 69 |
70 | 71 | The Affine transformation matrix can be used as input in the *warpAffine()* function, 72 | 73 | ```{r, eval = T} 74 | 75 | res_3d = warpAffine(img = img, 76 | M = M_aff, 77 | R = r, 78 | C = c, 79 | verbose = TRUE) 80 | 81 | str(res_3d) 82 | 83 | ``` 84 | 85 |
86 | 87 | The next image shows the output based on the input data and parameters, 88 | 89 | ```{r, out.width = "65%", out.height = "50%", fig.align = 'center', fig.cap = "Output of Warp Affine function", fig.alt="Output of Warp Affine function", echo = T, eval = T} 90 | 91 | imageShow(res_3d, clear_viewer = FALSE) 92 | 93 | ``` 94 | 95 |
96 | -------------------------------------------------------------------------------- /vignettes/vignette_1/image1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_1/image1.jpeg -------------------------------------------------------------------------------- /vignettes/vignette_1/image2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_1/image2.jpg -------------------------------------------------------------------------------- /vignettes/vignette_1/view1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_1/view1.jpg -------------------------------------------------------------------------------- /vignettes/vignette_1/view2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_1/view2.jpg -------------------------------------------------------------------------------- /vignettes/vignette_1/view3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_1/view3.jpg -------------------------------------------------------------------------------- /vignettes/vignette_2/car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_2/car.png -------------------------------------------------------------------------------- /vignettes/vignette_2/gabor_car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_2/gabor_car.png -------------------------------------------------------------------------------- /vignettes/vignette_2/gabor_car_thresholding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_2/gabor_car_thresholding.png -------------------------------------------------------------------------------- /vignettes/vignette_2/gabor_filter_bank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_2/gabor_filter_bank.png -------------------------------------------------------------------------------- /vignettes/vignette_3/BSR_bsds500_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/BSR_bsds500_image.jpg -------------------------------------------------------------------------------- /vignettes/vignette_3/BSR_bsds500_segmentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/BSR_bsds500_segmentation.png -------------------------------------------------------------------------------- /vignettes/vignette_3/airplane.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/airplane.jpg -------------------------------------------------------------------------------- /vignettes/vignette_3/im_masks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/im_masks.png -------------------------------------------------------------------------------- /vignettes/vignette_3/segment_AP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/segment_AP.png -------------------------------------------------------------------------------- /vignettes/vignette_3/segment_kmeans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/segment_kmeans.png -------------------------------------------------------------------------------- /vignettes/vignette_3/segment_mbkm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/segment_mbkm.png -------------------------------------------------------------------------------- /vignettes/vignette_3/slic_vs_slico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlampros/OpenImageR/59b3c72be79fcb38e8ce5cdd4678194fe8452ad6/vignettes/vignette_3/slic_vs_slico.png --------------------------------------------------------------------------------