在Java内存模型中发生并编程顺序(Happens before and program order in Java Memory Model)
我有一些关于程序的顺序以及它如何影响JMM中的重新排序。
在Java内存模型中,程序顺序( po )被定义为程序中每个线程的总操作顺序。 根据JLS ,这导致了发生之前( hb )边缘:
如果
x
和y
是同一个线程的动作,并且x
按照程序顺序在y
之前,那么hb(x,y) (即x
发生在y
之前)。所以对于一个简单的程序P:
initially, x = y = 0 T1 | T2 -----------|----------- 1. r1 = x | 3. r2 = y 2. y = 1 | 4. x = r2
我认为宝(1,2)和宝(3,4) 。 因此, hb(1,2)和hb(3,4) 。
现在假设我想对这些陈述重新排序,给我P':
initially, x = y = 0 T1 | T2 -----------|----------- 2. y = 1 | 3. r2 = y 1. r1 = x | 4. x = r2
根据本文 ,我们可以对任何两个相邻的语句(例如1和2)进行重新排序,前提是重新排序不会消除任何有效执行中的边缘之前发生的任何传递事件。 然而,由于hb是由po定义的(部分),而po是线程行为的全部顺序,所以在我看来,在不违反hb的情况下重新排序任何两个语句是不可能的,因此P'不是合法的转换。
我的问题是:
- 我对po和hb的理解是否正确,并且我是否正确地定义了po和hb关于上述程序P ?
- 我对hb失败问题重新排序的理解在哪里?
I have some regarding program order and how it affects reorderings in the JMM.
In the Java Memory Model, program order (po) is defined as the total order of actions in each thread in a program. According to the JLS, this induces happens-before (hb) edges:
If
x
andy
are actions of the same thread andx
comes beforey
in program order, then hb(x, y) (i.e.x
happens-beforey
).So for a simple program P:
initially, x = y = 0 T1 | T2 -----------|----------- 1. r1 = x | 3. r2 = y 2. y = 1 | 4. x = r2
I think po(1, 2) and po(3, 4). Thus, hb(1, 2) and hb(3, 4).
Now suppose I wanted to reorder some of these statements, giving me P':
initially, x = y = 0 T1 | T2 -----------|----------- 2. y = 1 | 3. r2 = y 1. r1 = x | 4. x = r2
According to this paper, we can reorder any two adjacent statements (e.g. 1 and 2), provided that the reordering doesn't eliminate any transitive happens-before edges in any valid execution. However, since hb is defined (partially) by po, and po is a total order over a thread's actions, it seems to me that it would be impossible to reorder any two statements without violating hb, thus P' is not a legal transformation.
My questions are:
- Is my understanding of po and hb correct, and have I correctly defined po and hb with respect to the above program P?
- Where is my understanding about reordering with regards to hb failing?
原文:https://stackoverflow.com/questions/32492621
最满意答案
你可能要找的是一个执行“直方图拉伸”的实用程序。 这是一个实现 。 我相信还有其他人。 我认为你想保留原来的色调,并将这个功能统一应用于所有色带。
当然,很有可能一些瓷砖在他们加入的层次上会有显着的不连续性。 但是,避免这种情况将涉及“拉伸”参数的空间插值,并且是更为复杂的解决方案。 (...但如果有这种需求,这将是一个很好的练习。)
编辑:
这是一个保存图像色调的调整:
import operator def equalize(im): h = im.convert("L").histogram() lut = [] for b in range(0, len(h), 256): # step size step = reduce(operator.add, h[b:b+256]) / 255 # create equalization lookup table n = 0 for i in range(256): lut.append(n / step) n = n + h[i+b] # map image through lookup table return im.point(lut*im.layers)
What you are probably looking for is a utility that performs "histogram stretching". Here is one implementation. I am sure there are others. I think you want to preserve the original hue and apply this function uniformly across all color bands.
Of course there is a good chance that some of the tiles will have a noticeable discontinuity in level where they join. Avoiding this, however, would involve spatial interpolation of the "stretch" parameters and is a much more involved solution. (...but would be a good exercise if there is that need.)
Edit:
Here is a tweak that preserves image hue:
import operator def equalize(im): h = im.convert("L").histogram() lut = [] for b in range(0, len(h), 256): # step size step = reduce(operator.add, h[b:b+256]) / 255 # create equalization lookup table n = 0 for i in range(256): lut.append(n / step) n = n + h[i+b] # map image through lookup table return im.point(lut*im.layers)
相关问答
更多-
PIL的Image.tostring()返回imgdata所需的确切数据的字符串。 我使用的typemap非常简单,但并不完美,我将在下面注明。 以下是我在Windows上创建的示例代码,该代码适用于我: sample.h typedef unsigned int uint32; typedef unsigned char uint8; typedef struct simple_image_t { uint32 rows; uint32 cols; uint8 *imgdata; ...
-
你可能要找的是一个执行“直方图拉伸”的实用程序。 这是一个实现 。 我相信还有其他人。 我认为你想保留原来的色调,并将这个功能统一应用于所有色带。 当然,很有可能一些瓷砖在他们加入的层次上会有显着的不连续性。 但是,避免这种情况将涉及“拉伸”参数的空间插值,并且是更为复杂的解决方案。 (...但如果有这种需求,这将是一个很好的练习。) 编辑: 这是一个保存图像色调的调整: import operator def equalize(im): h = im.convert("L").histogram ...
-
你可以看一看stsci库,它是用来比较和分析图像的。 它应该给你你想要的,但可能有点矫枉过正。 如果你想保持简单,你可以先减少颜色的数量和分辨率,然后计算距离。 You can take a look at the stsci library, it is made for comparing and analysing images. It should give you what you want but might be a little overkill. If ou want to keep it ...
-
在图像对齐之前首先进行亮度/对比度校正,反之亦然?(Brightness/contrast correction first before image alignment or vice versa?)[2022-11-19]
由于大多数成本函数用于对齐,我鼓励您进行预处理(值得注意的例外包括互信息)。 然而,findTransformEcc使用的增强互相关似乎对光度失真很强(引用http://ieeexplore.ieee.org/abstract/document/4515873/ :“在这项工作中,我们建议使用相关的修改版本系数作为图像对准问题的性能标准。所提出的修改具有对光度失真不变的理想特性。“)因此,在光度调整之前或之后应该很好。 With most cost functions for alignment, I'd ... -
开始编写这样的脚本的一个好方法是使用ImageJ的宏记录器 - 您可以使用Plugins > Macros > Record ...来启动它。 对于这个例子,我假设你已经将Record:选项框切换为JavaScript ,但是如果你更熟悉ImageJ宏语言或者用Java编写插件,其他人可能是更好的选择。 如果你打开你的图像并使用Image > Stacks > Set Slice ...并选择(比如)slice 20,你应该看到: imp.setSlice(20); ...出现在录音机中。 现在,如果运行 ...
-
使用Python的PIL,我如何增强图像的对比度/饱和度?(Using Python's PIL, how do I enhance the contrast/saturation of an image?)[2021-12-20]
由于PIL大部分已经死亡。 安装枕头叉, sudo pip install pillow ,并使用ImageEnhance模块http://pillow.readthedocs.org/en/3.0.x/reference/ImageEnhance.html >>> from PIL import Image, ImageEnhance >>> image = Image.open('downloads/jcfeb2011.jpg') >>> contrast = ImageEnhance.Contrast ... -
如何在directx中设置视频/图像的亮度和对比度以及饱和度(How to set brightness and contrast and saturation of video/Image in directx)[2023-01-18]
有两种方法可以实现这一点: 写/寻找一种能够处理你的有效载荷的亮度和对比度的效果DMO。 从渲染器获取IVMRMixerControl9并调用GetProcAmpControl 。 在这个MSDN线程中的更多信息。 There are two ways you can accomplish that: Write/Find a Effect DMO that will handle brightness and contrast on you payload. Get the IVMRMixerContro ... -
如果您的数据在3D数组中,则不需要循环它就可以执行此操作。 使用5个图像,比如说256 x 256,你应该能够构造一个arr.shape == (256, 256, 5)的数组。 我认为我最初的评论有点偏,但下面的例子应该这样做。 target_array = [] for file in os.listdir(timelapse_folder): frame = cv2.imread(timelapse_folder+file, 0) if target_array:#Not entir ...
-
您可以通过以下步骤以更简单/更有效的方式执行此操作: 步骤1:裁剪图像中要更改对比度的部分。 步骤2:对此裁剪图像应用适当的对比度/亮度变化。 步骤3:将更改的图像粘贴回原始图像。 // Step 1 int rect_x = originalImg.cols / 5; int rect_y = 0; int rect_width = originalImg.cols / 6; int rect_height = originalImg.rows; cv::Rect ROI(rect_x, rect_y, ...
-
我想你可以在scipy.ndimage使用形态函数,这是一个例子: import pylab as pl import numpy as np from scipy import ndimage img = pl.imread("Aet62.png")[:, :, 0].astype(np.uint8) img2 = ndimage.binary_erosion(img, iterations=40) img3 = ndimage.binary_dilation(img2, iterations=40) l ...