Smoothing jagged edges of an image
I would like to generate a skeleton out of an image. Since the edges that are generated using skimage
from the original image isn't smooth, the resulting skeleton
obtained from binary
has disconnected edges with knots.
import skimage
from skimage import data,io,filters
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage.filters import threshold_adaptive,threshold_mean
from skimage.morphology import binary_dilation
from skimage import feature
from skimage.morphology import skeletonize_3d
imgfile = "edit.jpg"
image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
thresh = threshold_mean(image)
binary = image > thresh
edges = filters.sobel(binary)
dilate = feature.canny(binary,sigma=0)
skeleton = skeletonize_3d(binary)
fig, axes = plt.subplots(nrows=2,ncols=2, figsize=(8, 2))
ax = axes.ravel()
ax[0].imshow(binary, cmap=plt.cm.gray)
ax[0].set_title('binarize')
ax[1].imshow(edges, cmap=plt.cm.gray)
ax[1].set_title('edges')
ax[2].imshow(dilate, cmap=plt.cm.gray)
ax[2].set_title('dilates')
ax[3].imshow(skeleton, cmap=plt.cm.gray)
ax[3].set_title('skeleton')
for a in ax:
a.axis('off')
plt.show()
I tried using dilate
to smoothen the jagged edges. But the contours in the skeleton
has two edges instead of a single edge that is desired.
I would like to ask for suggestions on how the edges can be smoothened to avoid knots and disconnected edges in the resulting skeleton
.
Input image
Output images
Edit:After using gaussian smoothing
binary = image > thresh
gaussian = skimage.filters.gaussian(binary)
skeleton = skeletonize_3d(gaussian)
python-3.x image-processing scikit-image
add a comment |
I would like to generate a skeleton out of an image. Since the edges that are generated using skimage
from the original image isn't smooth, the resulting skeleton
obtained from binary
has disconnected edges with knots.
import skimage
from skimage import data,io,filters
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage.filters import threshold_adaptive,threshold_mean
from skimage.morphology import binary_dilation
from skimage import feature
from skimage.morphology import skeletonize_3d
imgfile = "edit.jpg"
image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
thresh = threshold_mean(image)
binary = image > thresh
edges = filters.sobel(binary)
dilate = feature.canny(binary,sigma=0)
skeleton = skeletonize_3d(binary)
fig, axes = plt.subplots(nrows=2,ncols=2, figsize=(8, 2))
ax = axes.ravel()
ax[0].imshow(binary, cmap=plt.cm.gray)
ax[0].set_title('binarize')
ax[1].imshow(edges, cmap=plt.cm.gray)
ax[1].set_title('edges')
ax[2].imshow(dilate, cmap=plt.cm.gray)
ax[2].set_title('dilates')
ax[3].imshow(skeleton, cmap=plt.cm.gray)
ax[3].set_title('skeleton')
for a in ax:
a.axis('off')
plt.show()
I tried using dilate
to smoothen the jagged edges. But the contours in the skeleton
has two edges instead of a single edge that is desired.
I would like to ask for suggestions on how the edges can be smoothened to avoid knots and disconnected edges in the resulting skeleton
.
Input image
Output images
Edit:After using gaussian smoothing
binary = image > thresh
gaussian = skimage.filters.gaussian(binary)
skeleton = skeletonize_3d(gaussian)
python-3.x image-processing scikit-image
Did you try to combine 'thresholding' with 'erode/erosion' ? Not firm in skimage but generally a erode after a thresholding should thin down the liens w/o need of sobel/canny - not sure if that is what skeletonize_3d does internally... repeated thresholds && smothing the thresholded image with a gauss might help before doing the other steps.
– Patrick Artner
Nov 28 '18 at 12:33
@PatrickArtner I triedgaussian = skimage.filters.gaussian(binary)
andskeleton = skeletonize_3d(gaussian)
afterbinary = image > thresh
.Now the knots in theskeleton
has been removed.But the edge lines are not continuous.Could you please suggest how this can be improved?
– Natasha
Nov 28 '18 at 17:19
2
You should theshold thegaussian
variable in your edit before applying the skeletonization. Presumably the threshold should be lower than the oneskeletonize_3d
seems to use internally.
– Paul Brodersen
Dec 5 '18 at 14:11
add a comment |
I would like to generate a skeleton out of an image. Since the edges that are generated using skimage
from the original image isn't smooth, the resulting skeleton
obtained from binary
has disconnected edges with knots.
import skimage
from skimage import data,io,filters
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage.filters import threshold_adaptive,threshold_mean
from skimage.morphology import binary_dilation
from skimage import feature
from skimage.morphology import skeletonize_3d
imgfile = "edit.jpg"
image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
thresh = threshold_mean(image)
binary = image > thresh
edges = filters.sobel(binary)
dilate = feature.canny(binary,sigma=0)
skeleton = skeletonize_3d(binary)
fig, axes = plt.subplots(nrows=2,ncols=2, figsize=(8, 2))
ax = axes.ravel()
ax[0].imshow(binary, cmap=plt.cm.gray)
ax[0].set_title('binarize')
ax[1].imshow(edges, cmap=plt.cm.gray)
ax[1].set_title('edges')
ax[2].imshow(dilate, cmap=plt.cm.gray)
ax[2].set_title('dilates')
ax[3].imshow(skeleton, cmap=plt.cm.gray)
ax[3].set_title('skeleton')
for a in ax:
a.axis('off')
plt.show()
I tried using dilate
to smoothen the jagged edges. But the contours in the skeleton
has two edges instead of a single edge that is desired.
I would like to ask for suggestions on how the edges can be smoothened to avoid knots and disconnected edges in the resulting skeleton
.
Input image
Output images
Edit:After using gaussian smoothing
binary = image > thresh
gaussian = skimage.filters.gaussian(binary)
skeleton = skeletonize_3d(gaussian)
python-3.x image-processing scikit-image
I would like to generate a skeleton out of an image. Since the edges that are generated using skimage
from the original image isn't smooth, the resulting skeleton
obtained from binary
has disconnected edges with knots.
import skimage
from skimage import data,io,filters
import numpy as np
import cv2
import matplotlib.pyplot as plt
from skimage.filters import threshold_adaptive,threshold_mean
from skimage.morphology import binary_dilation
from skimage import feature
from skimage.morphology import skeletonize_3d
imgfile = "edit.jpg"
image = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
thresh = threshold_mean(image)
binary = image > thresh
edges = filters.sobel(binary)
dilate = feature.canny(binary,sigma=0)
skeleton = skeletonize_3d(binary)
fig, axes = plt.subplots(nrows=2,ncols=2, figsize=(8, 2))
ax = axes.ravel()
ax[0].imshow(binary, cmap=plt.cm.gray)
ax[0].set_title('binarize')
ax[1].imshow(edges, cmap=plt.cm.gray)
ax[1].set_title('edges')
ax[2].imshow(dilate, cmap=plt.cm.gray)
ax[2].set_title('dilates')
ax[3].imshow(skeleton, cmap=plt.cm.gray)
ax[3].set_title('skeleton')
for a in ax:
a.axis('off')
plt.show()
I tried using dilate
to smoothen the jagged edges. But the contours in the skeleton
has two edges instead of a single edge that is desired.
I would like to ask for suggestions on how the edges can be smoothened to avoid knots and disconnected edges in the resulting skeleton
.
Input image
Output images
Edit:After using gaussian smoothing
binary = image > thresh
gaussian = skimage.filters.gaussian(binary)
skeleton = skeletonize_3d(gaussian)
python-3.x image-processing scikit-image
python-3.x image-processing scikit-image
edited Nov 28 '18 at 17:25
Natasha
asked Nov 28 '18 at 11:59
NatashaNatasha
1059
1059
Did you try to combine 'thresholding' with 'erode/erosion' ? Not firm in skimage but generally a erode after a thresholding should thin down the liens w/o need of sobel/canny - not sure if that is what skeletonize_3d does internally... repeated thresholds && smothing the thresholded image with a gauss might help before doing the other steps.
– Patrick Artner
Nov 28 '18 at 12:33
@PatrickArtner I triedgaussian = skimage.filters.gaussian(binary)
andskeleton = skeletonize_3d(gaussian)
afterbinary = image > thresh
.Now the knots in theskeleton
has been removed.But the edge lines are not continuous.Could you please suggest how this can be improved?
– Natasha
Nov 28 '18 at 17:19
2
You should theshold thegaussian
variable in your edit before applying the skeletonization. Presumably the threshold should be lower than the oneskeletonize_3d
seems to use internally.
– Paul Brodersen
Dec 5 '18 at 14:11
add a comment |
Did you try to combine 'thresholding' with 'erode/erosion' ? Not firm in skimage but generally a erode after a thresholding should thin down the liens w/o need of sobel/canny - not sure if that is what skeletonize_3d does internally... repeated thresholds && smothing the thresholded image with a gauss might help before doing the other steps.
– Patrick Artner
Nov 28 '18 at 12:33
@PatrickArtner I triedgaussian = skimage.filters.gaussian(binary)
andskeleton = skeletonize_3d(gaussian)
afterbinary = image > thresh
.Now the knots in theskeleton
has been removed.But the edge lines are not continuous.Could you please suggest how this can be improved?
– Natasha
Nov 28 '18 at 17:19
2
You should theshold thegaussian
variable in your edit before applying the skeletonization. Presumably the threshold should be lower than the oneskeletonize_3d
seems to use internally.
– Paul Brodersen
Dec 5 '18 at 14:11
Did you try to combine 'thresholding' with 'erode/erosion' ? Not firm in skimage but generally a erode after a thresholding should thin down the liens w/o need of sobel/canny - not sure if that is what skeletonize_3d does internally... repeated thresholds && smothing the thresholded image with a gauss might help before doing the other steps.
– Patrick Artner
Nov 28 '18 at 12:33
Did you try to combine 'thresholding' with 'erode/erosion' ? Not firm in skimage but generally a erode after a thresholding should thin down the liens w/o need of sobel/canny - not sure if that is what skeletonize_3d does internally... repeated thresholds && smothing the thresholded image with a gauss might help before doing the other steps.
– Patrick Artner
Nov 28 '18 at 12:33
@PatrickArtner I tried
gaussian = skimage.filters.gaussian(binary)
and skeleton = skeletonize_3d(gaussian)
after binary = image > thresh
.Now the knots in the skeleton
has been removed.But the edge lines are not continuous.Could you please suggest how this can be improved?– Natasha
Nov 28 '18 at 17:19
@PatrickArtner I tried
gaussian = skimage.filters.gaussian(binary)
and skeleton = skeletonize_3d(gaussian)
after binary = image > thresh
.Now the knots in the skeleton
has been removed.But the edge lines are not continuous.Could you please suggest how this can be improved?– Natasha
Nov 28 '18 at 17:19
2
2
You should theshold the
gaussian
variable in your edit before applying the skeletonization. Presumably the threshold should be lower than the one skeletonize_3d
seems to use internally.– Paul Brodersen
Dec 5 '18 at 14:11
You should theshold the
gaussian
variable in your edit before applying the skeletonization. Presumably the threshold should be lower than the one skeletonize_3d
seems to use internally.– Paul Brodersen
Dec 5 '18 at 14:11
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%2f53518976%2fsmoothing-jagged-edges-of-an-image%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%2f53518976%2fsmoothing-jagged-edges-of-an-image%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
Did you try to combine 'thresholding' with 'erode/erosion' ? Not firm in skimage but generally a erode after a thresholding should thin down the liens w/o need of sobel/canny - not sure if that is what skeletonize_3d does internally... repeated thresholds && smothing the thresholded image with a gauss might help before doing the other steps.
– Patrick Artner
Nov 28 '18 at 12:33
@PatrickArtner I tried
gaussian = skimage.filters.gaussian(binary)
andskeleton = skeletonize_3d(gaussian)
afterbinary = image > thresh
.Now the knots in theskeleton
has been removed.But the edge lines are not continuous.Could you please suggest how this can be improved?– Natasha
Nov 28 '18 at 17:19
2
You should theshold the
gaussian
variable in your edit before applying the skeletonization. Presumably the threshold should be lower than the oneskeletonize_3d
seems to use internally.– Paul Brodersen
Dec 5 '18 at 14:11