numpy:根据多个条件将值设置为零(numpy: Setting values to zero based on multiple conditions)
我有一个RGB图像,我正在尝试使用类似下面的方法为它执行一个简单的阈值处理:
from skimage import filter def threshold(image): r = image[:, :, 0] g = image[:, :, 1] b = image[:, :, 2] rt = filter.threshold_otsu(r) gt = filter.threshold_otsu(g) bt = filter.threshold_otsu(b)
我现在要做的是制作一个二进制掩码,其中原始图像中小于这些阈值的RGB值应该设置为0。
mask = np.ones(r.shape)
我无法弄清楚如何做的是如何将掩码索引(x,y)设置为零
image[x, y, 0] < rt and image[x, y, 1] < gt and image [x, y, 2] < bt
不知怎的,我需要从这个原始图像中获得满足这个标准的(x,y)像素索引,但我不知道如何做到这一点。
I have an RGB image and I am trying to perform a simple thresholding for it using something like this:
from skimage import filter def threshold(image): r = image[:, :, 0] g = image[:, :, 1] b = image[:, :, 2] rt = filter.threshold_otsu(r) gt = filter.threshold_otsu(g) bt = filter.threshold_otsu(b)
What I would like to do is now make a binary mask where the RGB values in the original image which are less than these threshold value should be set to 0.
mask = np.ones(r.shape)
What I cannot figure out how to do is how do I set the mask indices (x, y) to zero where the
image[x, y, 0] < rt and image[x, y, 1] < gt and image [x, y, 2] < bt
Somehow I need to get the (x, y) pixel indices from this original image which meets this criteria but I am not sure how to do this.
原文:https://stackoverflow.com/questions/28279438
满意答案
你几乎是正确的。 唯一的区别是方向标志(
DF
)控制是否从EDI
增加或减去4(并且它实际上偏离了ES
段基础,但你可能不关心):for (; regs.d.ecx != 0; regs.d.ecx--) { *(unsigned int *)(regs.d.edi) = regs.d.eax; regs.d.edi += regs.eflags.df ? -4 : 4; }
请注意,
for (; regs.d.ecx != 0; regs.d.ecx--) { }
是REP
前缀的操作,循环的主体是STOS DWORD...
。由于您提出了很多这些问题,我认为您会发现英特尔64和IA-32架构软件开发人员手册第2A和2B卷非常有用。 这些包含每个指令和前缀的描述,包括伪代码描述。
You are almost correct. The only difference is that the direction flag (
DF
) controls whether 4 is added or subtracted fromEDI
(and it actually is offset from theES
segment base, but you probably don't care about that):for (; regs.d.ecx != 0; regs.d.ecx--) { *(unsigned int *)(regs.d.edi) = regs.d.eax; regs.d.edi += regs.eflags.df ? -4 : 4; }
Note that the
for (; regs.d.ecx != 0; regs.d.ecx--) { }
is the action of theREP
prefix, and the body of the loop is the action ofSTOS DWORD...
.Since you are asking a lot of these questions, I think you will find the Intel 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A and 2B to be useful. These contain descriptions of each instruction and prefix, including pseudo-code descriptions.
相关问答
更多“rep ret”是什么意思?(What does `rep ret` mean?)
提高ZeroMQ REQ / REP性能(Improve ZeroMQ REQ/REP performance)
汇编如何将REP STOS转换为C代码(Assembly How to convert REP STOS to C code)
为什么rep()与这个简单的R例子行为不一致?(why does rep() behave inconsistently with this simple R example?)
rep_movsl的Clobber列表(Clobber list for rep_movsl)
使用rep()函数(Working with the rep() function)
使用rep()创建列表(Create list using rep())
有没有理由使用没有重复前缀的MOVS / CMPS / STOS / SCAS?(Is there any reason to use MOVS/CMPS/STOS/SCAS without a repeat prefix?)
通过dplyr在组内应用rep()(Applying rep() within groups through dplyr)
V-REP的Lua`tonumber`在Linux上返回nil(V-REP's Lua `tonumber` returns nil on Linux)
相关文章
更多Java-based 实现的索引复制
Solr 4.6 | Setting Up an External ZooKeeper Ensemble | upgrade solr to Solr4.6
ext 的store中 baseParams.conditions 是什么意思啊?
Setting up Nutch 2.1 with MySQL to handle UTF-8
Guava Multimap类-映射到多个值
INSERT INTO blog_appitem (user_id,appid,app_secret,is_valid) VALUES (1, 'wxf415741de036114c','48e1e345fd5f11c93af18ff1714c7f78',1)
solr 从零学习开始
solr 从零学习开始
Solr4:Tomcat7与Solr之多核配置(Multiple Cores)
Guava Booleans类-布尔型基本的实用工具类
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!