Để có hình ảnh JPEG, bạn có thể sử dụng jpeg library và ggplot2 library.
Thông thường, tôi thấy hữu ích khi trục tốt nghiệp theo pixel và trục dọc sẽ chuyển sang hướng dương và hình ảnh giữ nguyên tỷ lệ khung hình gốc.Vì vậy, tôi có thể nạp R trực tiếp với đầu ra được tạo ra bởi thuật toán thị giác máy tính, ví dụ thuật toán có thể phát hiện lỗ đạn và trích xuất tọa độ lỗ từ ảnh chụp mục tiêu và sau đó R có thể vẽ biểu đồ 2D bằng cách sử dụng ảnh đích làm nền.
Mã của tôi là dựa trên mã bởi baptiste tìm thấy tại https://stackoverflow.com/a/16418186/15485
library(ggplot2)
library(jpeg)
img <- readJPEG("bersaglio.jpg") # http://www.tiropratico.com/bersagli/forme/avancarica.jpg
h<-dim(img)[1] # image height
w<-dim(img)[2] # image width
df<-data.frame(x=rnorm(100000,w/1.99,w/100),y=rnorm(100000,h/2.01,h/97))
plot(ggplot(df, aes(x,y)) +
annotation_custom(grid::rasterGrob(img, width=unit(1,"npc"), height=unit(1,"npc")), 0, w, 0, -h) + # The minus is needed to get the y scale reversed
scale_x_continuous(expand=c(0,0),limits=c(0,w)) +
scale_y_reverse(expand=c(0,0),limits=c(h,0)) + # The y scale is reversed because in image the vertical positive direction is typically downward
# Also note the limits where h>0 is the first parameter.
coord_equal() + # To keep the aspect ratio of the image.
stat_bin2d(binwidth=2,aes(fill = ..density..)) +
scale_fill_gradient(low = "dark red", high = "red")
)
df<-data.frame(x=rnorm(100000,100,w/70),y=rnorm(100000,400,h/100))
plot(ggplot(df, aes(x,y)) +
annotation_custom(grid::rasterGrob(img, width=unit(1,"npc"), height=unit(1,"npc")), 0, w, 0, -h) + # The minus is needed to get the y scale reversed
scale_x_continuous(expand=c(0,0),limits=c(0,w)) +
scale_y_reverse(expand=c(0,0),limits=c(h,0)) + # The y scale is reversed because in image the vertical positive direction is typically downward
# Also note the limits where h>0 is the first parameter.
coord_equal() + # To keep the aspect ratio of the image.
stat_bin2d(binwidth=2,aes(fill = ..density..)) +
scale_fill_gradient(low = "dark red", high = "red")
)
Tôi cố gắng để cài đặt gói RIMAGE trên 2.10 và 2.12.1, và có cùng một lỗi cả hai lần. Tôi đang sử dụng Windows XP: Cảnh báo: không thể truy cập chỉ mục cho kho lưu trữ http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10 Thông báo cảnh báo: Trong getDependencies (pkgs, dependencies , có sẵn, lib): gói 'vành' không có sẵn – Btibert3
@ Btibert3: Tôi có thể cài đặt cả hai mà không có sự cố từ www.freestatistics.org/cran. Hãy thử để có được một kho lưu trữ anyway, một trong những gương của cran được đề cập trên http://cran.r-project.org/mirrors.html sẽ làm. –
Máy tính xách tay của tôi có vấn đề vì một số lý do. Tôi vừa thử máy tính xách tay cá nhân của mình và nó được cài đặt mà không có vấn đề gì. Cuối cùng, tôi nên nói rằng đó là một tập tin GIF. – Btibert3