Comments (7)
I understand that you want to include this in the package but I would prefer to have then a separate method as in
image_contour_detector <- function(x, Q=2.0, ...){
UseMethod("image_contour_detector")
}
image_contour_detector.matrix <- function(x, Q, ...){
}
image_contour_detector.RasterLayer <- function(x, Q, ...){
}
image_contour_detector.SpatialGridDataFrame <- function(x, Q, ...){
}
In general there is certainly a looot of overlap possible between computer vision and spatial communities. The first thing on my mind would be a package which easily converts images between these 2 (especially covering things like r/g/b and that the topleft is (0,0) and regular R has bottomleft as (0,0).
This last should probably be in a different package so that it can easily switch between representations of R package magick, opencv, plain base arrays, sp, sf, raster... objects, HCR objects, textline objects andsoforth.
from image.
There is code at https://github.com/bnosac/image/blob/master/image.ContourDetector/R/contour_detector.R#L85:L88 which extracts the lines as an sp object, does that help you further?
from image.
many thanks!
I found it only later...now I'm trying to figure out how to refer them to the original georeferenced data.
What do the output's x
and y
refer to? I tried adding the minX
and minY
(lower left corner) but it seems that somewhere in the input process there's a sort of rescaling, in addition to the coords being lost. In this way I get lines with not real sizes and related to a relative reference system...
from image.
x and y correspond to the horizontal and vertical positions of the points defining the contour line
note that the magick R package the point (0,0) starts at the topleft
from image.
good to know!
BTW, I got a bit deeper and adapted your code to accept RasteLayers as well. I don't know if it might be of interest for your package but I think users using the tool on spatial data may appreciate it :) (there's quite a lot of room for your tools in such field)
image_contour_detector <- function(x, Q=2.0) {
if( is(r,"RasterLayer") ){
minX = raster::extent(x)[1]
minY = raster::extent(x)[3]
resol = raster::res(x)[1]
x = as.matrix(x)
} else { stopifnot(is.matrix(x)) }
if( anyNA(x) ){
x[is.na(x)] = 0
warning("NA values found and set to 0")
}
if( min(x, na.rm = TRUE)>=0 & max(x, na.rm = TRUE) <=255 ){ warning("Values range between 0 and 255: Q might be set to 0")}
contourlines <- image.ContourDetector:::detect_contours(x,
X=nrow(x),
Y=ncol(x),
Q=Q)
names(contourlines) <- c("x", "y", "curvelimits", "curves", "contourpoints")
contourlines$curvelimits <- contourlines$curvelimits+1L
from <- contourlines$curvelimits
to <- c(tail(contourlines$curvelimits, contourlines$curves-1L)-1L, contourlines$contourpoints)
curve <- unlist(mapply(seq_along(from), from, to, FUN=function(contourid, from, to) rep(contourid, to-from+1L), SIMPLIFY = FALSE))
contourlines$data <- data.frame(x = contourlines$y, y = nrow(x) - contourlines$x, curve_id = curve)
contourlines$data$x = contourlines$data$x * resol + minX
contourlines$data$y = contourlines$data$y * resol + minY
contourlines <- contourlines[c("curves", "contourpoints", "data")]
class(contourlines) <- "cld"
contourlines
}
An idea for further enhancement could be to add a "asSpatial" boolen option to get directly the spatial object, but probably that would be too specific for the general purpose..or not?
BTW thanks and keep up the good work!
from image.
unfortunately I can't help with methods, yet, because I didn't get my hands on the topic...but I hope to contribute in the next future!
I think it's really necessary to expand the capabilities of the package towards the other main representations of arrays
from image.
Fixed with merging #24
from image.
Related Issues (20)
- build notes
- Make wrapper around pretrained CNN https://github.com/ShiqiYu/libfacedetection
- image.libfacedetection fails with some images HOT 4
- implement densecrf
- Print output bounding boxes and labels from image_darknet_detect
- notes to myself
- Object recognition: apply *h5 cnn model to find an specific handwritten digit HOT 1
- [image.darknet] output error: file.exists(model) is not TRUE HOT 10
- Crash R session HOT 2
- CRAN issues HOT 2
- add DBoW2 HOT 2
- image_darknet_detect: "file" from memory object? HOT 1
- R crash when `union = T` in `image_line_segment_detector()` HOT 19
- how can I save the result of image_darknet_model into a R object? HOT 7
- installation error HOT 2
- namelist error on R HOT 4
- Session Crash HOT 9
- Line Segment Detector pixel matrix is 0 when union = T HOT 1
- image_surf only returns one non-zero dimension HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image.