温馨提示:本文翻译自stackoverflow.com,查看原文请点击:r - How to removing unduplicated data?

r - 如何删除重复数据?

发布于 2020-03-27 15:40:15

我尝试R中的对象检测问题。第一个数据是图像数据(RGB)。第二个是边界框信息(类,坐标...),但是有些图片没有边界框信息。所以我检查了一些文件。结果,这是不必要的。所以我想删除此数据。但是,对于加载图像文件,我无法删除文件目录。让我们来看看。

image_all <- list.files(img_dir, pattern = "png", full.names = TRUE)
head(image_all) #And then i use magick package in r. Load and resize file.
[1] "C:/Users/Sang won kim/Desktop/train/0.png"    "C:/Users/Sang won kim/Desktop/train/1.png"   
[3] "C:/Users/Sang won kim/Desktop/train/10.png"   "C:/Users/Sang won kim/Desktop/train/100.png" 
[5] "C:/Users/Sang won kim/Desktop/train/1000.png" "C:/Users/Sang won kim/Desktop/train/1001.png"
> head(bbox)
# A tibble: 6 x 12
  file_name class            x1           y1           x2           y2           x3           y3           x4          y4           
  <chr>     <chr>           <chr>        <chr>        <chr>        <chr>        <chr>        <chr>        <chr>       <chr>       <int>
1 0.png     4, 4, ~  166.9801643~ 150.2190229~ 167.1537030~ 146.5573567~ 185.2927712~ 147.4170282~ 185.119232~ 151.078694~ 
2 1.png     4, 4, ~  19.29481532~ 126.6060203~ 20.46862692~ 128.2216333~ 14.06897217~ 132.8712547~ 12.8951605~ 131.255641~  
3 10.png    1, 1, ~  99.69594772~ 187.4999087~ 102.1867698~ 191.0384564~ 84.99339110~ 203.1410626~ 82.5025689~ 199.602514~    
4 100.png   4, 4, 4  100.1321271~ 63.97578214~ 102.6031447~ 64.09151524~ 102.2166042~ 72.34454343~ 99.7455865~ 72.2288103~    
5 1000.png  1, 1     205.8749899~ 136.5865980~ 211.2637429~ 142.6596224~ 170.5469358~ 178.7887077~ 165.158182~ 172.715683~     
6 1001.png  1, 1     35.37469380~ 89.71580246~ 41.00788160~ 96.06430034~ -0.40033915~ 132.8068949~ -6.0335269~ 126.458397~   

我想要的是如果bbox的file_name不存在(与image_all相比),请删除image_all向量。

查看更多

查看更多

提问者
Sang won kim
被浏览
20
Rui Barradas 2020-01-31 16:04

这是一个问题match/subset但是在从中删除不需要的值之前image_all,请使用basename扩展名不带扩展名的文件sub

bn <- sub("\\..*$", "", basename(image_all))
i <- match(bbox$file_name, bn)
image_all <- image_all[i]

数据

image_all <- c("C:/Users/Sang won kim/Desktop/train/0.png","C:/Users/Sang won kim/Desktop/train/1.png",
"C:/Users/Sang won kim/Desktop/train/10.png","C:/Users/Sang won kim/Desktop/train/100.png",
"C:/Users/Sang won kim/Desktop/train/1000.png","C:/Users/Sang won kim/Desktop/train/1001.png")
file_name <- c("0", "1", "10", "1001")
bbox <- data.frame(file_name, stringsAsFactors = FALSE)

发布
问题

分享
好友

手机
浏览

扫码手机浏览