我正在做一个关于 Sobel 边缘检测的 R 作业。不幸的是,我遵循的视频教程使用 R 来完成所有其他任务,但切换到 python 进行图像处理 - 我猜测他没有找到任何有用的 R 包来进行图像卷积类型的工作(本教程来自去年)。我尝试过EBImage和magick(这个似乎是新的),但没有发现太多。这个神奇的小插图讨论了image_convolve('Sobel')(大约在页面的一半),但仅适用于垂直边缘,而不是水平边缘。有人可以推荐一些我可以使用的好材料吗?我对图像处理相当陌生。
更新:
我已经设法使用 magick 包(下面粘贴的代码)分别检测垂直和水平边缘,但不知道如何将它们组合起来生成单个图像
library(magick)
# get image
img <- image_read("https://www.r-project.org/logo/Rlogo.png")
print(image_info(img))
# define horizontal and vertical Sobel kernel
Shoriz <- matrix(c(1, 2, 1, 0, 0, 0, -1, -2, -1), nrow = 3)
Svert <- t(Shoriz)
# get horizontal and vertical edges
imgH <- image_convolve(img, Shoriz)
imgV <- image_convolve(img, Svert)
print(plot(as.raster(img))) # view original image
print(plot(as.raster(imgH))) # view horizontal …Run Code Online (Sandbox Code Playgroud) 有没有办法用 显示成对相关值seaborn.pairplot(),如下例所示(用ggpairs()in创建R)?我可以使用附加的代码制作绘图,但不能添加相关性。谢谢
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset('iris')
g = sns.pairplot(iris, kind='scatter', diag_kind='kde')
# remove upper triangle plots
for i, j in zip(*np.triu_indices_from(g.axes, 1)):
g.axes[i, j].set_visible(False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我正在尝试加载逗号分隔的数据文件,该文件在其一个文本列中也有逗号.以下示例代码生成这样一个文件'test.csv',,我将加载它read.csv()来说明我的问题.
> d <- data.frame(name = c("John Smith", "Smith, John"), age = c(34, 34))
> d
name age
1 John Smith 34
2 Smith, John 34
> write.csv(d, file = "test.csv", quote = F, row.names = F)
> d2 <- read.csv("test.csv")
> d2
name age
John Smith 34 NA
Smith John 34
Run Code Online (Sandbox Code Playgroud)
由于','in Smith, John,d2未正确分配.如何阅读文件以使其d2看起来完全一样d?
谢谢.
(在 64 位 Windows10 上使用最新的 miniconda + VS Code:)全新安装 VS Code 后,我无法再从其中启动 jupyter 笔记本。当我第一次尝试创建新的 jupyter 文件时,Python 扩展安装ipykernel在我的虚拟环境“da38”(我的主要工作环境)中。然后它会持续Connecting to IPython kernel: Connecting to kernel一段异常长的时间,并停止并显示错误消息Unable to start session for kernel Python 3.8.5 64-bit ('da38':conda)(下面粘贴的图像)。我还删除并重新创建了 da38 环境以防万一。之前曾多次使用 jupyter,没有出现任何问题,直到今天安装了新的 VS Code,并且在我的另一台计算机上也可以使用相同的设置。任何帮助表示赞赏。谢谢!
在下面的示例中,我如何使用seaborn.PairGrid()来重现创建的图seaborn.pairplot()?具体来说,我希望对角线分布跨越垂直轴。带白色边框等的标记也很棒。谢谢!
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset('iris')
# pairplot() example
g = sns.pairplot(iris, kind='scatter', diag_kind='kde')
plt.show()
# PairGrid() example
g = sns.PairGrid(iris)
g.map_diag(sns.kdeplot)
g.map_offdiag(plt.scatter)
plt.show()
Run Code Online (Sandbox Code Playgroud)
python ×3
r ×3
seaborn ×2
facet-grid ×1
ggpairs ×1
matplotlib ×1
miniconda ×1
read.csv ×1
sobel ×1