查找像素,使图像中的列表独特,可以提高蛮力?像素、图像、独特、列表

2023-09-11 22:51:53 作者:一听就很难过的 一看就很难过的id

假如我有一个字符串列表,其中每个字符串是

Suppose I have a list of strings where each string is

正好是4个字符长, 在列表中是唯一的。

有关每个这些字符串欲识别串内,使该字符串独特的字符的位置的

For each of these strings I want to identify the position of the characters within the string that make the string unique.

因此​​,对于三个字符串列表

So for a list of three strings

abcd
abcc
bbcb

有关的第一串我要识别的字符在第四位置的ð的自ð的未出现在任何其他字符串的第四位置。

For the first string I want to identify the character in 4th position d since d does not appear in the 4th position in any other string.

有关我想确定第四位字符的第二个字符串的 C 的。

For the second string I want to identify the character in 4th position c.

有关它,我要识别的字符在第一个位置的 B 的和字符在第4位,还的 B中的第三个字符串的。

For the third string it I want to identify the character in 1st position b AND the character in 4th position, also b.

这可能是简明重新psented为

This could be concisely represented as

abcd -> ...d
abcc -> ...c
bbcb -> b..b

如果你考虑同样的问题,但与二进制数的清单

If you consider the same problem but with a list of binary numbers

0101
0011
1111

然后我想会是这个结果。

Then the result I want would be

0101 -> ..0.
0011 -> .0..
1111 -> 1...

住用二进制的主题,我可以使用XOR以确定哪些位是在两个二进制数唯一的,因为

Staying with the binary theme I can use XOR to identify which bits are unique within two binary numbers since

0101 ^ 0011 = 0110

,我可以除$ P $角为意味着在这种情况下,第二和第三位(读数左至右)是这两个二进制数之间是唯一的。这种技术可能是一个红色的鲱鱼除非不知它可以扩展到更大的列表

which I can interpret as meaning that in this case the 2nd and 3rd bits (reading left to right) are unique between these two binary numbers. This technique might be a red herring unless somehow it can be extended to the larger list.

一个蛮力的方法是看每个字符串反过来,并为每个字符串遍历列表中的其余字符串的垂直切片。

A brute-force approach would be to look at each string in turn, and for each string to iterate through vertical slices of the remainder of the strings in the list.

因此​​,对于清单

abcd
abcc
bbcb

我将开始与

abcd

和遍历

abcc
bbcb

当这些垂直切片是

where these vertical slices would be

a | b | c | c
b | b | c | b

或以列表的形式,AB,BB,抄送,CB。

or in list form, "ab", "bb", "cc", "cb".

这将导致四个比较

a : ab -> . (a is not unique)
b : bb -> . (b is not unique)
c : cc -> . (c is not unique)
d : cb -> d (d is unique)

或简洁

abcd -> ...d

也许这是一厢情愿的想法,但我有一种感觉,应该有一个优雅和通用的解决方案将适用于字符串(或二进制数)的任意大名单。但是如果我还没有能够看到它。

Maybe it's wishful thinking, but I have a feeling that there should be an elegant and general solution that would apply to an arbitrarily large list of strings (or binary numbers). But if there is I haven't yet been able to see it.

我希望利用这个算法,以便有效地识别在未来某一时间这些图片来源于独特的图像(位图)集合最小的签名。如果未来的效率不是一个问题,我会用每幅图像的一个简单的哈希值。

I hope to use this algorithm to to derive minimal signatures from a collection of unique images (bitmaps) in order to efficiently identify those images at a future time. If future efficiency wasn't a concern I would use a simple hash of each image.

你能提高蛮力?

修改 我升温的方法是建立像素的地图影像

Edit The approach I'm warming to is building a map of pixels to images

sprawl[Tuple<x=10, y=33,color=f1fefd>] => {
     image17,
     image23,
     ...
}

sprawl[Tuple<x=10, y=34,color=f1fef0>] => {
     image11
     ...
}

和然后使用该地图来识别该组签名像素最小为每个图像

and then using that map to identify the minimal set of signature pixels for each image.

如果一个像素(由X,Y,颜色识别)引用只是一个图像,然后我找到了一个完美的(最小的)签名的形象。

If a pixel (identified by x, y, color) references just one image then I have found a perfect (minimal) signature for that image.

这是如果图像没有独特的像素比较复杂,但因为我知道,所有图像都在列表中是唯一的,我应该能够将两个或多个像素引用(但尽可能少),推算出图像。

It's more complicated if an image has no unique pixels, but since I know all images are unique within the list I should be able to combine two or more pixel references (but as few as possible) to deduce the image.

更新

我一直工作在算法这一点。我的问题是非常相似的这个,我已经写了我算法作为answer这个问题。此更新是为标志的人仍然以下(我看到五个书签)的注意。我工作的这个孤立所以任何和所有的反馈是值得欢迎的,哪怕只是去观察,我没有说清楚!

I've been working on an algorithm for this. My problem is very similar to this one, and I've written up my algorithm as an answer to that question. This update is to flag the attention of anyone still following (I see five bookmarks). I'm working on this in isolation so any and all feedback is welcome, even if just to observe that I haven't made myself clear!

推荐答案

可以产生一个二维阵列将包含各字符出现在每一个位置(0-3)的次数。例如,改编[1,3] 将包含的次数数字/字符 1 出现在最后的位置。

You can generate a two dimensional array which will contain the number of times each character appears in each position (0-3). For example, arr[1,3] will contain the number of times the digit/character 1 appears in the last position.

然后为每个字符串取值,去了所有字符的字符串研究。根据该数组中的位置,这仅出现一次的那些是唯一字符该字符串。换句话说,如果改编[S [I],I] == 1 然后串取值在位置独特

Then for each string s, go over all characters in the string. The ones which appear only once in that position according to the array are the unique characters for that string. In other words, if arr[s[i], i]==1 Then string s is unique in position i.

这会给你的线性时间的解决方案,而你给的算法需要二次的时间。

This will give you the solution in linear time, while the algorithm you gave will take quadratic time.