Pixel annomolies with scipy.ndimage.geometric_transform
I am attempting to implement a displacement map on a numpy image. Here is my implementation.
def displaceImage(img,displacementMap,distance=10,angle=45):
"""
NOTE: If displacementMap is smaller than img, then everthing out of bounds
is not displaced!
"""
angle=math.radians(angle)
img=numpyArray(img)
displacementMap=numpyArray(displacementMap)
if len(displacementMap.shape)>2:
# convert displacement map to grayscale
displacementMap=colorSpaces.grayscale(displacementMap)
def dissp(point):
"""
Called for each point in the array. Returns a same shaped tuple where it should go.
"""
if point[0]<displacementMap.shape[0] and point[1]<displacementMap.shape[1]:
delta=displacementMap[point[0],point[1]]*distance
toX=point[0]+delta*math.sin(angle)
toY=point[1]-delta*math.cos(angle)
if len(point)>2: # array is (w,h,rgb)
point=(toX,toY,point[2])
else: # array is (w,h) -- aka grayscale
point=(toX,toY)
return point
img=scipy.ndimage.geometric_transform(img,dissp,mode="nearest")
return img
And below I attempt to use a b&w perlin noise to displace to the top left quadrant of the image. As you can see from the central leaves/sky area, it appears to be doing what one would expect. The problem is, of course, the stray pixels everywhere. Thoughts?
python numpy scipy
add a comment |
I am attempting to implement a displacement map on a numpy image. Here is my implementation.
def displaceImage(img,displacementMap,distance=10,angle=45):
"""
NOTE: If displacementMap is smaller than img, then everthing out of bounds
is not displaced!
"""
angle=math.radians(angle)
img=numpyArray(img)
displacementMap=numpyArray(displacementMap)
if len(displacementMap.shape)>2:
# convert displacement map to grayscale
displacementMap=colorSpaces.grayscale(displacementMap)
def dissp(point):
"""
Called for each point in the array. Returns a same shaped tuple where it should go.
"""
if point[0]<displacementMap.shape[0] and point[1]<displacementMap.shape[1]:
delta=displacementMap[point[0],point[1]]*distance
toX=point[0]+delta*math.sin(angle)
toY=point[1]-delta*math.cos(angle)
if len(point)>2: # array is (w,h,rgb)
point=(toX,toY,point[2])
else: # array is (w,h) -- aka grayscale
point=(toX,toY)
return point
img=scipy.ndimage.geometric_transform(img,dissp,mode="nearest")
return img
And below I attempt to use a b&w perlin noise to displace to the top left quadrant of the image. As you can see from the central leaves/sky area, it appears to be doing what one would expect. The problem is, of course, the stray pixels everywhere. Thoughts?
python numpy scipy
Update: I thought that perhaps this was due to an uninitialized buffer, so I tried:bg=np.copy(img) img=scipy.ndimage.geometric_transform(img,dissp,output=bg,mode="nearest")
but it did not fix the problem
– TheHeadlessSourceMan
Jan 1 at 16:11
Update 2: I noticed that setting the geometric_transform to order=1 seemed to work, so I thought that perhaps the curve was developing a "ring" and clipping. Yet np.clip(img,0.0,1.0) doesn't help.
– TheHeadlessSourceMan
Jan 1 at 23:00
add a comment |
I am attempting to implement a displacement map on a numpy image. Here is my implementation.
def displaceImage(img,displacementMap,distance=10,angle=45):
"""
NOTE: If displacementMap is smaller than img, then everthing out of bounds
is not displaced!
"""
angle=math.radians(angle)
img=numpyArray(img)
displacementMap=numpyArray(displacementMap)
if len(displacementMap.shape)>2:
# convert displacement map to grayscale
displacementMap=colorSpaces.grayscale(displacementMap)
def dissp(point):
"""
Called for each point in the array. Returns a same shaped tuple where it should go.
"""
if point[0]<displacementMap.shape[0] and point[1]<displacementMap.shape[1]:
delta=displacementMap[point[0],point[1]]*distance
toX=point[0]+delta*math.sin(angle)
toY=point[1]-delta*math.cos(angle)
if len(point)>2: # array is (w,h,rgb)
point=(toX,toY,point[2])
else: # array is (w,h) -- aka grayscale
point=(toX,toY)
return point
img=scipy.ndimage.geometric_transform(img,dissp,mode="nearest")
return img
And below I attempt to use a b&w perlin noise to displace to the top left quadrant of the image. As you can see from the central leaves/sky area, it appears to be doing what one would expect. The problem is, of course, the stray pixels everywhere. Thoughts?
python numpy scipy
I am attempting to implement a displacement map on a numpy image. Here is my implementation.
def displaceImage(img,displacementMap,distance=10,angle=45):
"""
NOTE: If displacementMap is smaller than img, then everthing out of bounds
is not displaced!
"""
angle=math.radians(angle)
img=numpyArray(img)
displacementMap=numpyArray(displacementMap)
if len(displacementMap.shape)>2:
# convert displacement map to grayscale
displacementMap=colorSpaces.grayscale(displacementMap)
def dissp(point):
"""
Called for each point in the array. Returns a same shaped tuple where it should go.
"""
if point[0]<displacementMap.shape[0] and point[1]<displacementMap.shape[1]:
delta=displacementMap[point[0],point[1]]*distance
toX=point[0]+delta*math.sin(angle)
toY=point[1]-delta*math.cos(angle)
if len(point)>2: # array is (w,h,rgb)
point=(toX,toY,point[2])
else: # array is (w,h) -- aka grayscale
point=(toX,toY)
return point
img=scipy.ndimage.geometric_transform(img,dissp,mode="nearest")
return img
And below I attempt to use a b&w perlin noise to displace to the top left quadrant of the image. As you can see from the central leaves/sky area, it appears to be doing what one would expect. The problem is, of course, the stray pixels everywhere. Thoughts?
python numpy scipy
python numpy scipy
asked Jan 1 at 1:35
TheHeadlessSourceManTheHeadlessSourceMan
105110
105110
Update: I thought that perhaps this was due to an uninitialized buffer, so I tried:bg=np.copy(img) img=scipy.ndimage.geometric_transform(img,dissp,output=bg,mode="nearest")
but it did not fix the problem
– TheHeadlessSourceMan
Jan 1 at 16:11
Update 2: I noticed that setting the geometric_transform to order=1 seemed to work, so I thought that perhaps the curve was developing a "ring" and clipping. Yet np.clip(img,0.0,1.0) doesn't help.
– TheHeadlessSourceMan
Jan 1 at 23:00
add a comment |
Update: I thought that perhaps this was due to an uninitialized buffer, so I tried:bg=np.copy(img) img=scipy.ndimage.geometric_transform(img,dissp,output=bg,mode="nearest")
but it did not fix the problem
– TheHeadlessSourceMan
Jan 1 at 16:11
Update 2: I noticed that setting the geometric_transform to order=1 seemed to work, so I thought that perhaps the curve was developing a "ring" and clipping. Yet np.clip(img,0.0,1.0) doesn't help.
– TheHeadlessSourceMan
Jan 1 at 23:00
Update: I thought that perhaps this was due to an uninitialized buffer, so I tried:
bg=np.copy(img) img=scipy.ndimage.geometric_transform(img,dissp,output=bg,mode="nearest")
but it did not fix the problem– TheHeadlessSourceMan
Jan 1 at 16:11
Update: I thought that perhaps this was due to an uninitialized buffer, so I tried:
bg=np.copy(img) img=scipy.ndimage.geometric_transform(img,dissp,output=bg,mode="nearest")
but it did not fix the problem– TheHeadlessSourceMan
Jan 1 at 16:11
Update 2: I noticed that setting the geometric_transform to order=1 seemed to work, so I thought that perhaps the curve was developing a "ring" and clipping. Yet np.clip(img,0.0,1.0) doesn't help.
– TheHeadlessSourceMan
Jan 1 at 23:00
Update 2: I noticed that setting the geometric_transform to order=1 seemed to work, so I thought that perhaps the curve was developing a "ring" and clipping. Yet np.clip(img,0.0,1.0) doesn't help.
– TheHeadlessSourceMan
Jan 1 at 23:00
add a comment |
0
active
oldest
votes
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%2f53992526%2fpixel-annomolies-with-scipy-ndimage-geometric-transform%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53992526%2fpixel-annomolies-with-scipy-ndimage-geometric-transform%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
Update: I thought that perhaps this was due to an uninitialized buffer, so I tried:
bg=np.copy(img) img=scipy.ndimage.geometric_transform(img,dissp,output=bg,mode="nearest")
but it did not fix the problem– TheHeadlessSourceMan
Jan 1 at 16:11
Update 2: I noticed that setting the geometric_transform to order=1 seemed to work, so I thought that perhaps the curve was developing a "ring" and clipping. Yet np.clip(img,0.0,1.0) doesn't help.
– TheHeadlessSourceMan
Jan 1 at 23:00