- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有火焰照片 - 数据为包含像素矩阵的 asc 文件。每个像素中都是光强度值。
我的绘图代码:
import os
import numpy as np
import matplotlib.pyplot as plt
# Open a file
path = "input/"
dirs = os.listdir( path )
number_of_files = 0
# This would print all the files and directories
for file in dirs:
if file.endswith(".asc"):
img = np.genfromtxt (path+file)
file = os.path.splitext(file)[0]
#pasukamas vaizdas
img = img.transpose ()
# Just a figure and one subplot
fig, ax = plt.subplots(1,figsize=(20,20))
ax.set_title(file, fontsize=60, y=1.03)
plt.imshow (img, interpolation='nearest', origin='lower')
plt.colorbar ()
plt.savefig ('output/' + file + '.png', bbox_inches = 'tight')
number_of_files = number_of_files + 1
plt.close(fig)
print (number_of_files)
结果:
如何绘制 3 个范围内的图像:
并检测大多数底部和顶部像素?还有最左和最右的像素?然后用线连接顶部和底部像素。左右像素需要相同的东西。如何显示线条上的像素距离?
结果必须是这样的
最佳答案
您似乎想要图像的阈值版本,然后在阈值上进行区域标记,然后再进行一些奇特的测量。
<小时/>为了方便起见,我将形成图像序列的 3D ndarray ,以便可以使用 numpy 一次性完成任何操作:
fileList = filter(lambda s: s.endswith(".asc"), os.listdir(path))
# open first image so we have its dimensions to initialize the array
firstImage = np.genfromtxt (path+fileList[0])
imageArray = np.zeros((len(filelist),) + firstImage.shape)
现在我们分配值
imageArray[0,:,:] = firstImage
for i,file in enumerate(filelist[1:]):
# skip the first item because we already have it
imageArray[i+1,:,:] = np.genfromtxt (path+file)
<小时/>
好的,现在我们有了图像的 3D 数组,所以让我们获取范围图像
boolMaskRedzone = imageArray > 36000
boolMaskYellowzone = imageArray > 27000
boolMaskYellowzone = imageArray > 12000
这些现在是与图像大小相同但由 bool 值组成的蒙版。让我们来摆弄它:
redParts = image*boolMaskRedZone # images with 0 for thresholded values
plt.imshow(redParts[0,:,:],cmap="hot")
再次注意,redParts 和其他所有内容仍然是 3D,因此我们制作了数组的 2D View 以用于绘图目的。
<小时/>现在是简单/有趣的部分:标签!我们可以使用scipy.ndimage.measurements.label()
from scipy.ndimage import label
labelsRed, nbLabelsRed = label(boolMaskRedzone)
labelsRed 现在是一个以整数作为标签索引的数组。
理想情况下,我们应该有 nbLabelsRed == 1,如果没有,“岛屿”可以用以下方法关闭
from scipy.ndimage import morphology
closedLabels = morphology.binary_closing(labelsRed)
# fiddle with the optional iterations parameter if needed
我们可以通过使用 np.where 为我们提供像素位置,然后计算项目数量来计算标签面积 = 阈值区域:
x,y,z = np.where(labelsRed == 1) # x, y ,z are arrays
area = len(x) # the number of pixels that are brighter than red
至于计算顶部/底部最像素,如果您希望该线是对角线,那么它可能会变得很棘手,但如果您只想顶部/底部(与图像轴对齐),您可以在 mask 变为时进行 numpy 检查对于每个轴都是如此,这显然是在数组和偏移版本之间进行差异(推导),然后沿每个轴的第一个非零元素
differenceArray = boolMaskRedZone - np.roll(boolMaskRedZone,1,axis=1)
# now check along each column when the array first becomes True
uselessImageIndex,xTopMostPixel,yTopMostPixel= numpy.where(differenceArray == True)
# found all the crossings and put them in 2 arrays
<小时/>
为了精确的对角线测量,您可能需要查看专门的图像测量库,例如 scikit-image ,他们可能有你想要的
如果你真的想自己做,我会推荐一些基于查找对象中心、然后计算对角线位置并测量最大长度的方法,但是如果你找到 45 度线会发生什么?是“从上到下”还是“从左到右”?或者你想要接近水平线的最长线?或者您想要双正交测量? (选择最大的线作为第一次测量,第二条直径线是与第一条线成 90 度的线的长度)
假设你在图像中有你的点,绘图只是一个带有 plt.plot =) 的线图
我必须承认我没有对推导部分进行太多思考,但我认为一旦你拥有了标签,你就会成为一个快乐的露营者 =)
编辑:当然,所有这些操作都可以通过迭代数组来直接计算,但我只发布了一种使用 numpy 的数组操作效率来生成单行代码的方法。您确实可以通过执行
来完成每个操作for x in range(image.shape[0]):
for y in range(image.shape[1]):
if(image[x,y] > 36000):
mask[x,y]=True
但是与 numpy 的编译函数和硬件加速函数相比,这种循环嵌套非常慢(请参阅 http://www.astro.washington.edu/users/vanderplas/Astr599/notebooks/11_EfficientNumpy 了解 python/numpy 上的速度演示)
编辑 2:对于我的另一个项目,我一直在研究 scipy 的 ndimage 函数,并且有一些适合您的东西:ndimage.center_of_mass() .
此函数查找(可能已标记的)数组中的质心。通过找到标记数组的质心,您就可以找到对角线的轴中心,其余的只是小菜一碟^^
关于python - 如何检测并绘制 asc 文件的强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29637117/
我有一组类和它们从 AJAX 到 PHP 调用返回的日期。它作为“数据”返回,所以我们只调用我们的数组数据: var data = [{ "course": "First Aid", "cou
我正在开发音乐播放器,我想列出所有按艺术家从 A-Z (ASC) 排序的歌曲。信息存储在一个表中,包含艺术家、文件、歌曲等。 我尝试使用 while 循环首先按 A-Z 排序艺术家,然后按艺术家 A-
CREATE TABLE #cities(city_id INT, city_name VARCHAR(100)) INSERT INTO #cities(city_id,city_name) SEL
这似乎是一个典型的问题,但它是不同的。 我有一个带有 id 和 3 个时间戳字段的表(简单来说)。最初所有 3 个字段都是空的,并且它们被值填充。行的例子是: id time1 time2
我已经动态绑定(bind)了用于对列进行排序的图标,在这里,如果我单击其他列来对前一列进行排序,图标仍处于我单击的状态,但我希望该图标处于默认状态(当前排序除外)列,在这里要对我想要的新列进行排序,必
我在 Sql 中有一个这样的列名: 规范段落 1 2 3 4 5 ... 179 在我的程序中,我在第 1 行和第 2 行之间插入了一个新行。我的专栏现在是:规范款 1 3 4 5 ... 179 2
数据排序 asc、desc 1、单一字段排序order by 字段名称 作用: 通过哪个或哪些字段进行排序 含义: 排序采用 order by 子句,order by 后面跟上排序字段,排序字
我正在尝试在 python 中导入 .asc 文件以使用 shapefile 对其进行剪辑。对于剪辑,我将使用: import earthpy.clip as cl clip = cl.clip_sh
我目前正在尝试将各种“ASC”文件中的信息提取到 R 中,以便对数据进行分析。 问题是我不确定如何准确读取文件。我尝试了标准的 read.table 函数,但所有数字都完全相同 (-9999.00)。
我想首先获取特定位置的所有配置文件: SELECT * FROM profile WHERE location IN ('a', 'b', 'c') OR isDefault=1 ORDER BY l
按 ASC 排序的正确语法是什么? 错误 1 当前上下文中不存在名称“ASC” public IEnumerable GetGrid(String ShipNumber) {
我有一个使用以下查询的 google 电子表格: =query('Respostas do Formulário 1'!A1:AG;"select D,G,H,I,J,K,L,M,N,O,P,Q,R,
我有火焰照片 - 数据为包含像素矩阵的 asc 文件。每个像素中都是光强度值。 我的绘图代码: import os import numpy as np import matplotlib.pyplo
我不知道如何正确排序我的选择选项值。我的选择元素返回文本值,如下所示: ** Please choose 2-3 pers. 16-18 pers. 20-24 pers 3-4 pers. 4-6
我的 SQL 查询有问题。我希望我的结果按升序排序,但问题是数据库只根据第一个数字对结果进行排序,而逻辑上,例如 2 应该在 19 之前。 这是我的请求和结果的屏幕截图,但根本没有成功: SELECT
如果我有此查询,我需要有关此数据的帮助 SELECT count(*),username FROM products WHERE description LIKE '%Yes%' or descrip
我的 Laravel 查询 $items = TypeServices::whereIn('id', $serviceIdEvent)
我正在使用 compact framework 3.5 我的文件.cs public class Cases : IEnumerable { private Hashtable cases =
我的 elasticsearch 有问题。 设置:拥有一个带有数据字段“companyName”的公司类。我的搜索将搜索并响应所有具有搜索词的公司。 如果我尝试通过排序 .Sort(x=> x.OnF
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我是一名优秀的程序员,十分优秀!