我是Python初学者。我正在尝试切换 matlab 中的一些程序。我需要求解一个刚性颂方程,其输入都是矩阵。在matlab中我使用
[ttT,uT] = ode23s('SST',t,fT);
Run Code Online (Sandbox Code Playgroud) 我正在搜索内在的fortran函数来帮助我找到带有零或其他值的数组索引.我只发现了minloc功能,但我认为这不合适.在Fortran中是否有matlab查找函数?
谢谢
我正在尝试计算值的第8个根平方或^ ^/8,但是numpy总是返回错误的值
temp = 141.18
h2 = temp ** (1/8)
h2_ = np.power(temp, (1/8))
Run Code Online (Sandbox Code Playgroud)
我的输出总是1.0.我也试过了方形命令.我需要使用numpy,我在mycode中使用其他numpy数组,只是为了保持兼容.
是否可以仅使用纯python或wand等python模块将png文件转换为SVG文件?
更准确地说,我想将png转换为真实的矢量图形,我不想在svg内嵌入位图,我想转换为图形代码。
我知道使用Illustrator或Inkscape可以实现,但是我需要一个自动化的过程。
谢谢 !
但是,它有一些噪音。我怎样才能消除噪音?我做了一个特写来更清楚我想表达的意思

代码:
rMaskgray = cv2.imread('redmask.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
(thresh, binRed) = cv2.threshold(rMaskgray, 50, 255, cv2.THRESH_BINARY)
Rcontours, hier_r = cv2.findContours(binRed,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
r_areas = [cv2.contourArea(c) for c in Rcontours]
max_rarea = np.max(r_areas)
CntExternalMask = np.ones(binRed.shape[:2], dtype="uint8") * 255
for c in Rcontours:
if(( cv2.contourArea(c) > max_rarea * 0.70) and (cv2.contourArea(c)< max_rarea)):
cv2.drawContours(CntExternalMask,[c],-1,0,1)
cv2.imwrite('contour1.jpg', CntExternalMask)
Run Code Online (Sandbox Code Playgroud) 我想用python编写相当于Matlab中的这段代码,
zeta = zeros(1,5)
alpha=[1e5,1e3,1e5,1e7,1e3];
dz = 0.001;
for i=1:length(zeta)
zeta(i) = alpha(i)/(dz*dz);
end
Run Code Online (Sandbox Code Playgroud)
编辑:感谢所有答案,它们都非常有用,并且正在帮助理解python如何工作,并且似乎也是Matlab; 因为我没有得到数组和矩阵运算的全部功能.我的初始编程语言是C.
现在,我正在尝试计算如何在python循环和数组操作中进行编码.如果你能提供帮助.(zeta来自上一个代码)
nl= 7;
l=[0.3,0.1,0.2,0.1,0.1,0.1,0.3)
wz=zeros(1,nl); %layer width
temp=0; %auxiliary temp variable
for i=1:nl
wz(i)=l(1,i)*(nz-1)+temp;
temp=wz(1,i);
end
Run Code Online (Sandbox Code Playgroud) 如何使用 python opencv 绘制/保存图像的内部轮廓?我知道如何获得最大的轮廓,我想保存它和内部孔,它们也是轮廓。
import numpy as np
import cv2
from matplotlib import pyplot as plt
rgb = cv2.imread('MIL_NPGERBV2.png')
grayImg = cv2.imread('MIL_NPGERBV2.png', cv2.CV_LOAD_IMAGE_GRAYSCALE)
#to apply properly contour algorithm we need convert to binary
(thresh, bwImage) = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
img1 = rgb.copy()
img2 = rgb.copy()
contours, hierarchy = cv2.findContours(bwImage,cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
#show all contours
cv2.drawContours(img1, contours, -1, (0,255,0), 2)
out = np.hstack([img1])
cv2.imshow('Output', out)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud) 有没有一种简单直接的方法从opencv 3.1 python中提取图像的内部轮廓(孔)?
我知道我可以用"区域"作为条件.但是,如果我更改图像分辨率,则"区域"不一样.
_, contours, hier_ = cv2.findContours(img,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
areas = [cv2.contourArea(c) for c in millCnts]
max_area = np.max(areas)
Mask = np.ones(img.shape[:2], dtype="uint8") * 255
# I can do something like this (currently not working, just to show an example)
for c in contours:
if(( cv2.contourArea(c) > 8) and (cv2.contourArea(c)< 100000)):
cv2.drawContours(Mask ,[c],-1,0,1)
Run Code Online (Sandbox Code Playgroud)