How to classify edges with enclosed boundaries or not in Matlab?2019 Community Moderator ElectionHow to determine edges in an image optimally?How do I find Waldo with Mathematica?Representing and solving a maze given an imageSupposed easy edge detection in MATLABCreate mask from bwtraceboundary in MatlabMATLAB: adaptive sobel-like edge detectionHow to extend a set of points in MATLABHow to control the order of detected objects by regionprops in matlab?segmenting an object from background using MATLAB based on feature pointsFinding location of corner points at starting and ending of curvature(matlab)
Use Mercury as quenching liquid for swords?
Does an unused member variable take up memory?
How can I portion out frozen cookie dough?
What is the orbit and expected lifetime of Crew Dragon trunk?
Insult for someone who "doesn't know anything"
An Undercover Army
Should I file my taxes? No income, unemployed, but paid 2k in student loan interest
Should I apply for my boss's promotion?
Why isn't P and P/poly trivially the same?
Is there a logarithm base for which the logarithm becomes an identity function?
How to distinguish easily different soldier of ww2?
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
Is the differential, dp, exact or not?
What does *dead* mean in *What do you mean, dead?*?
Can the Witch Sight warlock invocation see through the Mirror Image spell?
The (Easy) Road to Code
Help! My Character is too much for her story!
Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell
Is it appropriate to ask a former professor to order a library book for me through ILL?
Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?
What exactly is the meaning of "fine wine"?
Do I need a return ticket to Canada if I'm a Japanese National?
Why restrict private health insurance?
What would be the most expensive material to an intergalactic society?
How to classify edges with enclosed boundaries or not in Matlab?
2019 Community Moderator ElectionHow to determine edges in an image optimally?How do I find Waldo with Mathematica?Representing and solving a maze given an imageSupposed easy edge detection in MATLABCreate mask from bwtraceboundary in MatlabMATLAB: adaptive sobel-like edge detectionHow to extend a set of points in MATLABHow to control the order of detected objects by regionprops in matlab?segmenting an object from background using MATLAB based on feature pointsFinding location of corner points at starting and ending of curvature(matlab)
I have the following image (replaced by the better image under EDIT):
If I use bwboundaries
on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object
If I use bwboundaries
on the second object (the horizontal white line), the boundary is just a horizontal line.
I was hoping there was a way that bwboundaries
or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end
However, if I look closely at how bwboundaries
traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.
How can I fix this problem for bwboundaries
for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?
EDIT:
This is a better image
matlab image-processing edge-detection
add a comment |
I have the following image (replaced by the better image under EDIT):
If I use bwboundaries
on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object
If I use bwboundaries
on the second object (the horizontal white line), the boundary is just a horizontal line.
I was hoping there was a way that bwboundaries
or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end
However, if I look closely at how bwboundaries
traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.
How can I fix this problem for bwboundaries
for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?
EDIT:
This is a better image
matlab image-processing edge-detection
As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?
– Luis Mendo
2 days ago
If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons
– user5739619
2 days ago
yes, I already know aboutregionprops
. I don't see how any of its properties would allow me to classify lines vs blobs
– user5739619
2 days ago
Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons
– user5739619
2 days ago
From here:B = bwboundaries(BW)
traces the exterior boundaries of objects[...], and Thebwboundaries
function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.
– HansHirse
2 days ago
add a comment |
I have the following image (replaced by the better image under EDIT):
If I use bwboundaries
on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object
If I use bwboundaries
on the second object (the horizontal white line), the boundary is just a horizontal line.
I was hoping there was a way that bwboundaries
or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end
However, if I look closely at how bwboundaries
traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.
How can I fix this problem for bwboundaries
for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?
EDIT:
This is a better image
matlab image-processing edge-detection
I have the following image (replaced by the better image under EDIT):
If I use bwboundaries
on the first object (the white blob), I would expect the boundary to traverse the outer part of that first white object
If I use bwboundaries
on the second object (the horizontal white line), the boundary is just a horizontal line.
I was hoping there was a way that bwboundaries
or some other method can somehow classify these 2 objects differently. That is, it could say the first object's boundary starts and ends at the same point, while for the second object, it starts at the left end and ends at the right end
However, if I look closely at how bwboundaries
traverses these objects, I notice that for the first object, it traverses it once for 360 degrees. But for the second object, it actually starts at the left image border, goes to the right image border, AND THEN BACK towards the left image border.
How can I fix this problem for bwboundaries
for the 2nd object AND correctly classify these as different objects (the 1st one's boundary should start and end at same point, the 2nd one's boundary SHOULD start and end at DIFFERENT points)?
EDIT:
This is a better image
matlab image-processing edge-detection
matlab image-processing edge-detection
edited 2 days ago
user5739619
asked 2 days ago
user5739619user5739619
4931919
4931919
As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?
– Luis Mendo
2 days ago
If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons
– user5739619
2 days ago
yes, I already know aboutregionprops
. I don't see how any of its properties would allow me to classify lines vs blobs
– user5739619
2 days ago
Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons
– user5739619
2 days ago
From here:B = bwboundaries(BW)
traces the exterior boundaries of objects[...], and Thebwboundaries
function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.
– HansHirse
2 days ago
add a comment |
As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?
– Luis Mendo
2 days ago
If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons
– user5739619
2 days ago
yes, I already know aboutregionprops
. I don't see how any of its properties would allow me to classify lines vs blobs
– user5739619
2 days ago
Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons
– user5739619
2 days ago
From here:B = bwboundaries(BW)
traces the exterior boundaries of objects[...], and Thebwboundaries
function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.
– HansHirse
2 days ago
As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?
– Luis Mendo
2 days ago
As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?
– Luis Mendo
2 days ago
If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons
– user5739619
2 days ago
If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons
– user5739619
2 days ago
yes, I already know about
regionprops
. I don't see how any of its properties would allow me to classify lines vs blobs– user5739619
2 days ago
yes, I already know about
regionprops
. I don't see how any of its properties would allow me to classify lines vs blobs– user5739619
2 days ago
Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons
– user5739619
2 days ago
Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons
– user5739619
2 days ago
From here:
B = bwboundaries(BW)
traces the exterior boundaries of objects[...], and The bwboundaries
function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.– HansHirse
2 days ago
From here:
B = bwboundaries(BW)
traces the exterior boundaries of objects[...], and The bwboundaries
function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.– HansHirse
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y)
coordinates. For 1d objects, most (if not all) (x, y)
values should be present two times. So, for each boundary, we just determine the unique
values, or to be more precise the unique
rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95
should be a 2d object since most values are unique, and ratio < 0.55
should be a 1d object as most values were present two times.
img = uint8(zeros(100));
img(10:20, 10:90) = 255;
img(80, 10:90) = 255;
imshow(img);
upperThr = 0.95;
lowerThr = 0.55;
B = bwboundaries(img);
for k = 1:numel(B)
b = Bk;
origLength = size(b, 1);
b = unique(b, 'rows');
uniqueLength = size(b, 1);
ratio = uniqueLength / origLength;
printf('Object %d: ', k);
if (ratio > upperThr)
printf('2d objectn');
elseif (ratio < lowerThr)
printf('1d objectn');
else
printf('No idean');
end
end
There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)
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%2f55028061%2fhow-to-classify-edges-with-enclosed-boundaries-or-not-in-matlab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y)
coordinates. For 1d objects, most (if not all) (x, y)
values should be present two times. So, for each boundary, we just determine the unique
values, or to be more precise the unique
rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95
should be a 2d object since most values are unique, and ratio < 0.55
should be a 1d object as most values were present two times.
img = uint8(zeros(100));
img(10:20, 10:90) = 255;
img(80, 10:90) = 255;
imshow(img);
upperThr = 0.95;
lowerThr = 0.55;
B = bwboundaries(img);
for k = 1:numel(B)
b = Bk;
origLength = size(b, 1);
b = unique(b, 'rows');
uniqueLength = size(b, 1);
ratio = uniqueLength / origLength;
printf('Object %d: ', k);
if (ratio > upperThr)
printf('2d objectn');
elseif (ratio < lowerThr)
printf('1d objectn');
else
printf('No idean');
end
end
There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)
add a comment |
So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y)
coordinates. For 1d objects, most (if not all) (x, y)
values should be present two times. So, for each boundary, we just determine the unique
values, or to be more precise the unique
rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95
should be a 2d object since most values are unique, and ratio < 0.55
should be a 1d object as most values were present two times.
img = uint8(zeros(100));
img(10:20, 10:90) = 255;
img(80, 10:90) = 255;
imshow(img);
upperThr = 0.95;
lowerThr = 0.55;
B = bwboundaries(img);
for k = 1:numel(B)
b = Bk;
origLength = size(b, 1);
b = unique(b, 'rows');
uniqueLength = size(b, 1);
ratio = uniqueLength / origLength;
printf('Object %d: ', k);
if (ratio > upperThr)
printf('2d objectn');
elseif (ratio < lowerThr)
printf('1d objectn');
else
printf('No idean');
end
end
There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)
add a comment |
So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y)
coordinates. For 1d objects, most (if not all) (x, y)
values should be present two times. So, for each boundary, we just determine the unique
values, or to be more precise the unique
rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95
should be a 2d object since most values are unique, and ratio < 0.55
should be a 1d object as most values were present two times.
img = uint8(zeros(100));
img(10:20, 10:90) = 255;
img(80, 10:90) = 255;
imshow(img);
upperThr = 0.95;
lowerThr = 0.55;
B = bwboundaries(img);
for k = 1:numel(B)
b = Bk;
origLength = size(b, 1);
b = unique(b, 'rows');
uniqueLength = size(b, 1);
ratio = uniqueLength / origLength;
printf('Object %d: ', k);
if (ratio > upperThr)
printf('2d objectn');
elseif (ratio < lowerThr)
printf('1d objectn');
else
printf('No idean');
end
end
There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)
So, I came up with the following idea: For 2d objects, the boundary has most likely unique (x, y)
coordinates. For 1d objects, most (if not all) (x, y)
values should be present two times. So, for each boundary, we just determine the unique
values, or to be more precise the unique
rows, and check if the amount has significantly decreased, e.g. using a ratio (#unique rows) / (#all rows). A simple option would be to set up one or more thresholds for the ratio, e.g. ratio > 0.95
should be a 2d object since most values are unique, and ratio < 0.55
should be a 1d object as most values were present two times.
img = uint8(zeros(100));
img(10:20, 10:90) = 255;
img(80, 10:90) = 255;
imshow(img);
upperThr = 0.95;
lowerThr = 0.55;
B = bwboundaries(img);
for k = 1:numel(B)
b = Bk;
origLength = size(b, 1);
b = unique(b, 'rows');
uniqueLength = size(b, 1);
ratio = uniqueLength / origLength;
printf('Object %d: ', k);
if (ratio > upperThr)
printf('2d objectn');
elseif (ratio < lowerThr)
printf('1d objectn');
else
printf('No idean');
end
end
There's plenty of space for code improvements, I wanted to be keep it readable and easy to follow. One-liner fetishists are welcome to do what they like. ;-)
edited 2 days ago
answered 2 days ago
HansHirseHansHirse
54513
54513
add a comment |
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%2f55028061%2fhow-to-classify-edges-with-enclosed-boundaries-or-not-in-matlab%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
As I see it, the distinction between those two classes of objects may not be well defined. If the line was two pixels wide, to what class would it belong to?
– Luis Mendo
2 days ago
If the line is two pixels wide, it doesn't matter to me which class it belongs to. I just need a way to distinguish a line that is one pixel wide from general blobs/polygons
– user5739619
2 days ago
yes, I already know about
regionprops
. I don't see how any of its properties would allow me to classify lines vs blobs– user5739619
2 days ago
Just to clarify, the one pixel wide object doesn't have to be a straight line. It could be a curve or bent line, like the updated image I placed under EDIT. This one-pixel wide object should still be classified differently than blobs/polygons
– user5739619
2 days ago
From here:
B = bwboundaries(BW)
traces the exterior boundaries of objects[...], and Thebwboundaries
function implements the Moore-Neighbor tracing algorithm [...]. Therefore, look wikipedia. In short: Contour is 3x3 neighbourhood by definition, thus even for 1-pixel wide objects you have a closed path.– HansHirse
2 days ago