How to scale a binary mask pattern
DISCLAIMER:
I am doing this for an art project that combines history with mathematics.
QUESTION:
Let's say I have a binary mask pattern like
mask = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
it is a 5 rows 5 columns matrix that represents a swastika pattern
I am wondering if there are any quick ways of obtaining an "enlarged-scaled" version of the pattern
enlarged_mask = [1,0,0,1,1,1,1], [1,0,0,1,0,0,0], [1,0,0,1,0,0,0], [1,1,1,1,1,1,1], [0,0,0,1,0,0,1], [0,0,0,1,0,0,1], [1,1,1,1,0,0,1]
that in this case has now 7 rows and 7 columns and preserves the overall logic of the original pattern.
What could be a possible handy method for the case?
Any help would be highly appreciated
python matrix scaling binary-data
add a comment |
DISCLAIMER:
I am doing this for an art project that combines history with mathematics.
QUESTION:
Let's say I have a binary mask pattern like
mask = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
it is a 5 rows 5 columns matrix that represents a swastika pattern
I am wondering if there are any quick ways of obtaining an "enlarged-scaled" version of the pattern
enlarged_mask = [1,0,0,1,1,1,1], [1,0,0,1,0,0,0], [1,0,0,1,0,0,0], [1,1,1,1,1,1,1], [0,0,0,1,0,0,1], [0,0,0,1,0,0,1], [1,1,1,1,0,0,1]
that in this case has now 7 rows and 7 columns and preserves the overall logic of the original pattern.
What could be a possible handy method for the case?
Any help would be highly appreciated
python matrix scaling binary-data
2
This question is unclear, because "the overall logic of the original pattern" is not clear. There are infinitely many logics that apply to the original pattern, and it is not at all obvious which one should be used in enlarging the pattern. Could you be more specific?
– Rory Daulton
Jan 3 at 1:41
Is using a image processing module an option? If it is, you could do this by converting the binary data into a bitmapped image file, scale it, and then converting the result back into zeros and ones.
– martineau
Jan 3 at 2:35
add a comment |
DISCLAIMER:
I am doing this for an art project that combines history with mathematics.
QUESTION:
Let's say I have a binary mask pattern like
mask = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
it is a 5 rows 5 columns matrix that represents a swastika pattern
I am wondering if there are any quick ways of obtaining an "enlarged-scaled" version of the pattern
enlarged_mask = [1,0,0,1,1,1,1], [1,0,0,1,0,0,0], [1,0,0,1,0,0,0], [1,1,1,1,1,1,1], [0,0,0,1,0,0,1], [0,0,0,1,0,0,1], [1,1,1,1,0,0,1]
that in this case has now 7 rows and 7 columns and preserves the overall logic of the original pattern.
What could be a possible handy method for the case?
Any help would be highly appreciated
python matrix scaling binary-data
DISCLAIMER:
I am doing this for an art project that combines history with mathematics.
QUESTION:
Let's say I have a binary mask pattern like
mask = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
it is a 5 rows 5 columns matrix that represents a swastika pattern
I am wondering if there are any quick ways of obtaining an "enlarged-scaled" version of the pattern
enlarged_mask = [1,0,0,1,1,1,1], [1,0,0,1,0,0,0], [1,0,0,1,0,0,0], [1,1,1,1,1,1,1], [0,0,0,1,0,0,1], [0,0,0,1,0,0,1], [1,1,1,1,0,0,1]
that in this case has now 7 rows and 7 columns and preserves the overall logic of the original pattern.
What could be a possible handy method for the case?
Any help would be highly appreciated
python matrix scaling binary-data
python matrix scaling binary-data
edited Jan 3 at 2:30
Loss of human identity
asked Jan 3 at 1:35


Loss of human identityLoss of human identity
1,24511028
1,24511028
2
This question is unclear, because "the overall logic of the original pattern" is not clear. There are infinitely many logics that apply to the original pattern, and it is not at all obvious which one should be used in enlarging the pattern. Could you be more specific?
– Rory Daulton
Jan 3 at 1:41
Is using a image processing module an option? If it is, you could do this by converting the binary data into a bitmapped image file, scale it, and then converting the result back into zeros and ones.
– martineau
Jan 3 at 2:35
add a comment |
2
This question is unclear, because "the overall logic of the original pattern" is not clear. There are infinitely many logics that apply to the original pattern, and it is not at all obvious which one should be used in enlarging the pattern. Could you be more specific?
– Rory Daulton
Jan 3 at 1:41
Is using a image processing module an option? If it is, you could do this by converting the binary data into a bitmapped image file, scale it, and then converting the result back into zeros and ones.
– martineau
Jan 3 at 2:35
2
2
This question is unclear, because "the overall logic of the original pattern" is not clear. There are infinitely many logics that apply to the original pattern, and it is not at all obvious which one should be used in enlarging the pattern. Could you be more specific?
– Rory Daulton
Jan 3 at 1:41
This question is unclear, because "the overall logic of the original pattern" is not clear. There are infinitely many logics that apply to the original pattern, and it is not at all obvious which one should be used in enlarging the pattern. Could you be more specific?
– Rory Daulton
Jan 3 at 1:41
Is using a image processing module an option? If it is, you could do this by converting the binary data into a bitmapped image file, scale it, and then converting the result back into zeros and ones.
– martineau
Jan 3 at 2:35
Is using a image processing module an option? If it is, you could do this by converting the binary data into a bitmapped image file, scale it, and then converting the result back into zeros and ones.
– martineau
Jan 3 at 2:35
add a comment |
2 Answers
2
active
oldest
votes
preserves the overall logic of the original pattern.
This is the hard bit, assuming you want an arbitrary pattern. You're basically after an AI capable of discerning this pattern, a very much non-trivial task. For example, consider the 3x3 pattern (zeros are rendered blank for readabilty):
111
1 1
111
Is this pattern "outer units set" or is it "inner unit clear"? The difference between those two is vast as the former is what you want but the latter will end up with a much thicker border line. In other words, it will be one of:
Outer-set Inner-clear
========= ===========
11111 11111
1 1 11111
1 1 11 11
1 1 11111
11111 11111
That's even before you examine other possibilities such as simply scaling the image itself, so that you work on sub-unit resolution.
However, since it appears you're after a specific pattern (known in advance), you can generate a single-pixel width swastika with the following code:
def swastika(n):
# Ignore requests for malformed images.
if n < 1 or n % 2 == 0: return
matrix = [[0 for _ in range(n)] for _ in range(n)]
# Do the cross bit.
for i in range(n):
matrix[n//2][i] = 1
matrix[i][n//2] = 1
# Do the outer arms.
for i in range(n//2,n):
matrix[0][i] = 1
matrix[i][n-1] = 1
matrix[n-1][n-i-1] = 1
matrix[n-i-1][0] = 1
return matrix
# Test harness for various sizes.
for i in range(5, 10, 2):
s = swastika(i)
for j in range(i):
print(s[j])
print()
The output of that is (modified for readability, yet again):
1 11111
1 1111 1 1
1 111 1 1 1 1
1 1 1 1 1 1
11111 1111111 111111111
1 1 1 1 1 1
111 1 1 1 1 1
1111 1 1 1
11111 1
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
I'm trying to scale a swastika-pattern for an art project. I could edit my question with thematrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?
– Loss of human identity
Jan 3 at 2:08
1
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
|
show 1 more comment
It looks like you just want a 2D matrix with the very outer edges set. In numpy:
import numpy as np
n = 5 # or 3 or whatever
mask = np.ones((n, n), dtype=int)
mask[1:-1,1:-1] = 0
print(mask)
Result:
array([[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]])
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015307%2fhow-to-scale-a-binary-mask-pattern%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
preserves the overall logic of the original pattern.
This is the hard bit, assuming you want an arbitrary pattern. You're basically after an AI capable of discerning this pattern, a very much non-trivial task. For example, consider the 3x3 pattern (zeros are rendered blank for readabilty):
111
1 1
111
Is this pattern "outer units set" or is it "inner unit clear"? The difference between those two is vast as the former is what you want but the latter will end up with a much thicker border line. In other words, it will be one of:
Outer-set Inner-clear
========= ===========
11111 11111
1 1 11111
1 1 11 11
1 1 11111
11111 11111
That's even before you examine other possibilities such as simply scaling the image itself, so that you work on sub-unit resolution.
However, since it appears you're after a specific pattern (known in advance), you can generate a single-pixel width swastika with the following code:
def swastika(n):
# Ignore requests for malformed images.
if n < 1 or n % 2 == 0: return
matrix = [[0 for _ in range(n)] for _ in range(n)]
# Do the cross bit.
for i in range(n):
matrix[n//2][i] = 1
matrix[i][n//2] = 1
# Do the outer arms.
for i in range(n//2,n):
matrix[0][i] = 1
matrix[i][n-1] = 1
matrix[n-1][n-i-1] = 1
matrix[n-i-1][0] = 1
return matrix
# Test harness for various sizes.
for i in range(5, 10, 2):
s = swastika(i)
for j in range(i):
print(s[j])
print()
The output of that is (modified for readability, yet again):
1 11111
1 1111 1 1
1 111 1 1 1 1
1 1 1 1 1 1
11111 1111111 111111111
1 1 1 1 1 1
111 1 1 1 1 1
1111 1 1 1
11111 1
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
I'm trying to scale a swastika-pattern for an art project. I could edit my question with thematrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?
– Loss of human identity
Jan 3 at 2:08
1
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
|
show 1 more comment
preserves the overall logic of the original pattern.
This is the hard bit, assuming you want an arbitrary pattern. You're basically after an AI capable of discerning this pattern, a very much non-trivial task. For example, consider the 3x3 pattern (zeros are rendered blank for readabilty):
111
1 1
111
Is this pattern "outer units set" or is it "inner unit clear"? The difference between those two is vast as the former is what you want but the latter will end up with a much thicker border line. In other words, it will be one of:
Outer-set Inner-clear
========= ===========
11111 11111
1 1 11111
1 1 11 11
1 1 11111
11111 11111
That's even before you examine other possibilities such as simply scaling the image itself, so that you work on sub-unit resolution.
However, since it appears you're after a specific pattern (known in advance), you can generate a single-pixel width swastika with the following code:
def swastika(n):
# Ignore requests for malformed images.
if n < 1 or n % 2 == 0: return
matrix = [[0 for _ in range(n)] for _ in range(n)]
# Do the cross bit.
for i in range(n):
matrix[n//2][i] = 1
matrix[i][n//2] = 1
# Do the outer arms.
for i in range(n//2,n):
matrix[0][i] = 1
matrix[i][n-1] = 1
matrix[n-1][n-i-1] = 1
matrix[n-i-1][0] = 1
return matrix
# Test harness for various sizes.
for i in range(5, 10, 2):
s = swastika(i)
for j in range(i):
print(s[j])
print()
The output of that is (modified for readability, yet again):
1 11111
1 1111 1 1
1 111 1 1 1 1
1 1 1 1 1 1
11111 1111111 111111111
1 1 1 1 1 1
111 1 1 1 1 1
1111 1 1 1
11111 1
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
I'm trying to scale a swastika-pattern for an art project. I could edit my question with thematrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?
– Loss of human identity
Jan 3 at 2:08
1
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
|
show 1 more comment
preserves the overall logic of the original pattern.
This is the hard bit, assuming you want an arbitrary pattern. You're basically after an AI capable of discerning this pattern, a very much non-trivial task. For example, consider the 3x3 pattern (zeros are rendered blank for readabilty):
111
1 1
111
Is this pattern "outer units set" or is it "inner unit clear"? The difference between those two is vast as the former is what you want but the latter will end up with a much thicker border line. In other words, it will be one of:
Outer-set Inner-clear
========= ===========
11111 11111
1 1 11111
1 1 11 11
1 1 11111
11111 11111
That's even before you examine other possibilities such as simply scaling the image itself, so that you work on sub-unit resolution.
However, since it appears you're after a specific pattern (known in advance), you can generate a single-pixel width swastika with the following code:
def swastika(n):
# Ignore requests for malformed images.
if n < 1 or n % 2 == 0: return
matrix = [[0 for _ in range(n)] for _ in range(n)]
# Do the cross bit.
for i in range(n):
matrix[n//2][i] = 1
matrix[i][n//2] = 1
# Do the outer arms.
for i in range(n//2,n):
matrix[0][i] = 1
matrix[i][n-1] = 1
matrix[n-1][n-i-1] = 1
matrix[n-i-1][0] = 1
return matrix
# Test harness for various sizes.
for i in range(5, 10, 2):
s = swastika(i)
for j in range(i):
print(s[j])
print()
The output of that is (modified for readability, yet again):
1 11111
1 1111 1 1
1 111 1 1 1 1
1 1 1 1 1 1
11111 1111111 111111111
1 1 1 1 1 1
111 1 1 1 1 1
1111 1 1 1
11111 1
preserves the overall logic of the original pattern.
This is the hard bit, assuming you want an arbitrary pattern. You're basically after an AI capable of discerning this pattern, a very much non-trivial task. For example, consider the 3x3 pattern (zeros are rendered blank for readabilty):
111
1 1
111
Is this pattern "outer units set" or is it "inner unit clear"? The difference between those two is vast as the former is what you want but the latter will end up with a much thicker border line. In other words, it will be one of:
Outer-set Inner-clear
========= ===========
11111 11111
1 1 11111
1 1 11 11
1 1 11111
11111 11111
That's even before you examine other possibilities such as simply scaling the image itself, so that you work on sub-unit resolution.
However, since it appears you're after a specific pattern (known in advance), you can generate a single-pixel width swastika with the following code:
def swastika(n):
# Ignore requests for malformed images.
if n < 1 or n % 2 == 0: return
matrix = [[0 for _ in range(n)] for _ in range(n)]
# Do the cross bit.
for i in range(n):
matrix[n//2][i] = 1
matrix[i][n//2] = 1
# Do the outer arms.
for i in range(n//2,n):
matrix[0][i] = 1
matrix[i][n-1] = 1
matrix[n-1][n-i-1] = 1
matrix[n-i-1][0] = 1
return matrix
# Test harness for various sizes.
for i in range(5, 10, 2):
s = swastika(i)
for j in range(i):
print(s[j])
print()
The output of that is (modified for readability, yet again):
1 11111
1 1111 1 1
1 111 1 1 1 1
1 1 1 1 1 1
11111 1111111 111111111
1 1 1 1 1 1
111 1 1 1 1 1
1111 1 1 1
11111 1
edited Jan 3 at 3:11
answered Jan 3 at 1:44


paxdiablopaxdiablo
643k17612671688
643k17612671688
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
I'm trying to scale a swastika-pattern for an art project. I could edit my question with thematrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?
– Loss of human identity
Jan 3 at 2:08
1
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
|
show 1 more comment
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
I'm trying to scale a swastika-pattern for an art project. I could edit my question with thematrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?
– Loss of human identity
Jan 3 at 2:08
1
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
@Loss: sure, if the rule is known in advance rather than trying to discern the rule from a bitmap. Otherwise, see my paragraph re "Anything other than a fixed pattern will, as mentioned, require a fair bit of AI." :-)
– paxdiablo
Jan 3 at 2:04
I'm trying to scale a swastika-pattern for an art project. I could edit my question with the
matrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?– Loss of human identity
Jan 3 at 2:08
I'm trying to scale a swastika-pattern for an art project. I could edit my question with the
matrix = [1,0,1,1,1],[1,0,1,0,0],[1,1,1,1,1],[0,0,1,0,1],[1,1,1,0,1]
I sent you. Could be possible for you to elaborate your answer in order to do so?– Loss of human identity
Jan 3 at 2:08
1
1
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
@Loss, see the update. I've added a section for the specific requirement.
– paxdiablo
Jan 3 at 2:35
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
Thank you a lot, it did the job perfectly. Do you think the overall thickness of the lines could also be preserved in the function implementation? Namely, not having the pattern get skinnier and skinnier at the increase of n but preserve a overall acceptable thickness.
– Loss of human identity
Jan 3 at 2:57
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
@Loss, it could be, yes. However, I'd suggest asking that as another question, linking back to this if needed. I've already had to make massive changes to the answer based on your question edits so I'd prefer not to have to do that again. Preserving the thickness will basically mean figuring out the ration of line width to image size (ratio of 1:6) but ensuring that width is always the closest integer. That's best done as a separate issue, I think.
– paxdiablo
Jan 3 at 3:15
|
show 1 more comment
It looks like you just want a 2D matrix with the very outer edges set. In numpy:
import numpy as np
n = 5 # or 3 or whatever
mask = np.ones((n, n), dtype=int)
mask[1:-1,1:-1] = 0
print(mask)
Result:
array([[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]])
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
add a comment |
It looks like you just want a 2D matrix with the very outer edges set. In numpy:
import numpy as np
n = 5 # or 3 or whatever
mask = np.ones((n, n), dtype=int)
mask[1:-1,1:-1] = 0
print(mask)
Result:
array([[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]])
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
add a comment |
It looks like you just want a 2D matrix with the very outer edges set. In numpy:
import numpy as np
n = 5 # or 3 or whatever
mask = np.ones((n, n), dtype=int)
mask[1:-1,1:-1] = 0
print(mask)
Result:
array([[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]])
It looks like you just want a 2D matrix with the very outer edges set. In numpy:
import numpy as np
n = 5 # or 3 or whatever
mask = np.ones((n, n), dtype=int)
mask[1:-1,1:-1] = 0
print(mask)
Result:
array([[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]])
answered Jan 3 at 1:47
Tomothy32Tomothy32
8,5931728
8,5931728
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
add a comment |
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
"It looks like you just want a 2D matrix with the very outer edges set", no. The pattern specified in the question is just an example case.I am interested in algorithms able to solve the generic scenario
– Loss of human identity
Jan 3 at 1:48
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
In that case, the question is far too broad to be answered. There is no simple algorithm to discern a pattern, especially from a measly 3x3 array.
– Tomothy32
Jan 3 at 1:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015307%2fhow-to-scale-a-binary-mask-pattern%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
This question is unclear, because "the overall logic of the original pattern" is not clear. There are infinitely many logics that apply to the original pattern, and it is not at all obvious which one should be used in enlarging the pattern. Could you be more specific?
– Rory Daulton
Jan 3 at 1:41
Is using a image processing module an option? If it is, you could do this by converting the binary data into a bitmapped image file, scale it, and then converting the result back into zeros and ones.
– martineau
Jan 3 at 2:35