General approach for extracting specific lines or line segments in an image
I have this sample cropped image:
I need to make black thick lines (horizontal and vertical) disappear or extracted while leave all other info intact. These specific lines are either 4 or 5 pixels thick. I tried:
- Simple filtering of rows having more zeros/ones if image is read as NumPy array but the filtering condition doesn't terminate till a single row is left with zero or one.
- Erosion with simple kernel (3,3) but it leaves some noise because some symbols are also thick black
- Dilation with line structuring element of the width of image width but there are overwhelming variations on line segments' sizes connecting different symbols that the basic info about each small line segment is lost.
Can someone give insights or directions about what kind of structuring elements, what type of morphological ops should be considered or may be any other clever heuristics? The output, if extraction of thick black lines is done, will then look like this grid of random line segments:
matlab opencv image-processing image-morphology
|
show 5 more comments
I have this sample cropped image:
I need to make black thick lines (horizontal and vertical) disappear or extracted while leave all other info intact. These specific lines are either 4 or 5 pixels thick. I tried:
- Simple filtering of rows having more zeros/ones if image is read as NumPy array but the filtering condition doesn't terminate till a single row is left with zero or one.
- Erosion with simple kernel (3,3) but it leaves some noise because some symbols are also thick black
- Dilation with line structuring element of the width of image width but there are overwhelming variations on line segments' sizes connecting different symbols that the basic info about each small line segment is lost.
Can someone give insights or directions about what kind of structuring elements, what type of morphological ops should be considered or may be any other clever heuristics? The output, if extraction of thick black lines is done, will then look like this grid of random line segments:
matlab opencv image-processing image-morphology
The "thick black lines" you speak of... They appear to have a height or width that's higher than the other lines, yes?
– rayryeng
Nov 14 '18 at 7:21
3
You should look into Hough transformation - after erosion, it is probably possible to detect the straight lines left
– T A
Nov 14 '18 at 7:47
1
what about erosion, followed by lineSegmentDetector? The noise should hopefully not build up line segments?
– Micka
Nov 14 '18 at 7:49
4
An ideal solution as picture would be helpful, otherwise e.g. "thick horizontal line" is ambiguous.
– Vroomfondel
Nov 14 '18 at 9:45
1
I think the expected output would be desirable... Or else we are all going to propose solutions that may not be what you want. Please update your question to provide what the expected output is.
– rayryeng
Nov 14 '18 at 20:21
|
show 5 more comments
I have this sample cropped image:
I need to make black thick lines (horizontal and vertical) disappear or extracted while leave all other info intact. These specific lines are either 4 or 5 pixels thick. I tried:
- Simple filtering of rows having more zeros/ones if image is read as NumPy array but the filtering condition doesn't terminate till a single row is left with zero or one.
- Erosion with simple kernel (3,3) but it leaves some noise because some symbols are also thick black
- Dilation with line structuring element of the width of image width but there are overwhelming variations on line segments' sizes connecting different symbols that the basic info about each small line segment is lost.
Can someone give insights or directions about what kind of structuring elements, what type of morphological ops should be considered or may be any other clever heuristics? The output, if extraction of thick black lines is done, will then look like this grid of random line segments:
matlab opencv image-processing image-morphology
I have this sample cropped image:
I need to make black thick lines (horizontal and vertical) disappear or extracted while leave all other info intact. These specific lines are either 4 or 5 pixels thick. I tried:
- Simple filtering of rows having more zeros/ones if image is read as NumPy array but the filtering condition doesn't terminate till a single row is left with zero or one.
- Erosion with simple kernel (3,3) but it leaves some noise because some symbols are also thick black
- Dilation with line structuring element of the width of image width but there are overwhelming variations on line segments' sizes connecting different symbols that the basic info about each small line segment is lost.
Can someone give insights or directions about what kind of structuring elements, what type of morphological ops should be considered or may be any other clever heuristics? The output, if extraction of thick black lines is done, will then look like this grid of random line segments:
matlab opencv image-processing image-morphology
matlab opencv image-processing image-morphology
edited Nov 14 '18 at 20:35
SKR
asked Nov 14 '18 at 6:05
SKRSKR
768
768
The "thick black lines" you speak of... They appear to have a height or width that's higher than the other lines, yes?
– rayryeng
Nov 14 '18 at 7:21
3
You should look into Hough transformation - after erosion, it is probably possible to detect the straight lines left
– T A
Nov 14 '18 at 7:47
1
what about erosion, followed by lineSegmentDetector? The noise should hopefully not build up line segments?
– Micka
Nov 14 '18 at 7:49
4
An ideal solution as picture would be helpful, otherwise e.g. "thick horizontal line" is ambiguous.
– Vroomfondel
Nov 14 '18 at 9:45
1
I think the expected output would be desirable... Or else we are all going to propose solutions that may not be what you want. Please update your question to provide what the expected output is.
– rayryeng
Nov 14 '18 at 20:21
|
show 5 more comments
The "thick black lines" you speak of... They appear to have a height or width that's higher than the other lines, yes?
– rayryeng
Nov 14 '18 at 7:21
3
You should look into Hough transformation - after erosion, it is probably possible to detect the straight lines left
– T A
Nov 14 '18 at 7:47
1
what about erosion, followed by lineSegmentDetector? The noise should hopefully not build up line segments?
– Micka
Nov 14 '18 at 7:49
4
An ideal solution as picture would be helpful, otherwise e.g. "thick horizontal line" is ambiguous.
– Vroomfondel
Nov 14 '18 at 9:45
1
I think the expected output would be desirable... Or else we are all going to propose solutions that may not be what you want. Please update your question to provide what the expected output is.
– rayryeng
Nov 14 '18 at 20:21
The "thick black lines" you speak of... They appear to have a height or width that's higher than the other lines, yes?
– rayryeng
Nov 14 '18 at 7:21
The "thick black lines" you speak of... They appear to have a height or width that's higher than the other lines, yes?
– rayryeng
Nov 14 '18 at 7:21
3
3
You should look into Hough transformation - after erosion, it is probably possible to detect the straight lines left
– T A
Nov 14 '18 at 7:47
You should look into Hough transformation - after erosion, it is probably possible to detect the straight lines left
– T A
Nov 14 '18 at 7:47
1
1
what about erosion, followed by lineSegmentDetector? The noise should hopefully not build up line segments?
– Micka
Nov 14 '18 at 7:49
what about erosion, followed by lineSegmentDetector? The noise should hopefully not build up line segments?
– Micka
Nov 14 '18 at 7:49
4
4
An ideal solution as picture would be helpful, otherwise e.g. "thick horizontal line" is ambiguous.
– Vroomfondel
Nov 14 '18 at 9:45
An ideal solution as picture would be helpful, otherwise e.g. "thick horizontal line" is ambiguous.
– Vroomfondel
Nov 14 '18 at 9:45
1
1
I think the expected output would be desirable... Or else we are all going to propose solutions that may not be what you want. Please update your question to provide what the expected output is.
– rayryeng
Nov 14 '18 at 20:21
I think the expected output would be desirable... Or else we are all going to propose solutions that may not be what you want. Please update your question to provide what the expected output is.
– rayryeng
Nov 14 '18 at 20:21
|
show 5 more comments
1 Answer
1
active
oldest
votes
This is how you erode the image and extract hough lines:
I=rgb2gray(imread('https://i.stack.imgur.com/cbHFL.jpg'));
Ibw=I>200;
imshow(Ibw)
SE=strel('disk',1)
Ier=imerode(~Ibw,SE);
[H,T,R] = hough(Ier);
P = houghpeaks(H,100,'threshold',ceil(0.1*max(H(:))));
lines = houghlines(Ier,T,R,P);
%% plot
imshow(I);hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','blue');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
From here, you can start thinking on what to delete. This is not straightforward unless you have a dictionary of symbols, e.g. how do you delete the line around the structures with >-<
shape? do you delete all the middle pixels or do you keep the entire middle thin bar? You can only know this if you know how the symbol should be without the thick lines.
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
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%2f53294066%2fgeneral-approach-for-extracting-specific-lines-or-line-segments-in-an-image%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
This is how you erode the image and extract hough lines:
I=rgb2gray(imread('https://i.stack.imgur.com/cbHFL.jpg'));
Ibw=I>200;
imshow(Ibw)
SE=strel('disk',1)
Ier=imerode(~Ibw,SE);
[H,T,R] = hough(Ier);
P = houghpeaks(H,100,'threshold',ceil(0.1*max(H(:))));
lines = houghlines(Ier,T,R,P);
%% plot
imshow(I);hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','blue');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
From here, you can start thinking on what to delete. This is not straightforward unless you have a dictionary of symbols, e.g. how do you delete the line around the structures with >-<
shape? do you delete all the middle pixels or do you keep the entire middle thin bar? You can only know this if you know how the symbol should be without the thick lines.
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
add a comment |
This is how you erode the image and extract hough lines:
I=rgb2gray(imread('https://i.stack.imgur.com/cbHFL.jpg'));
Ibw=I>200;
imshow(Ibw)
SE=strel('disk',1)
Ier=imerode(~Ibw,SE);
[H,T,R] = hough(Ier);
P = houghpeaks(H,100,'threshold',ceil(0.1*max(H(:))));
lines = houghlines(Ier,T,R,P);
%% plot
imshow(I);hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','blue');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
From here, you can start thinking on what to delete. This is not straightforward unless you have a dictionary of symbols, e.g. how do you delete the line around the structures with >-<
shape? do you delete all the middle pixels or do you keep the entire middle thin bar? You can only know this if you know how the symbol should be without the thick lines.
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
add a comment |
This is how you erode the image and extract hough lines:
I=rgb2gray(imread('https://i.stack.imgur.com/cbHFL.jpg'));
Ibw=I>200;
imshow(Ibw)
SE=strel('disk',1)
Ier=imerode(~Ibw,SE);
[H,T,R] = hough(Ier);
P = houghpeaks(H,100,'threshold',ceil(0.1*max(H(:))));
lines = houghlines(Ier,T,R,P);
%% plot
imshow(I);hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','blue');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
From here, you can start thinking on what to delete. This is not straightforward unless you have a dictionary of symbols, e.g. how do you delete the line around the structures with >-<
shape? do you delete all the middle pixels or do you keep the entire middle thin bar? You can only know this if you know how the symbol should be without the thick lines.
This is how you erode the image and extract hough lines:
I=rgb2gray(imread('https://i.stack.imgur.com/cbHFL.jpg'));
Ibw=I>200;
imshow(Ibw)
SE=strel('disk',1)
Ier=imerode(~Ibw,SE);
[H,T,R] = hough(Ier);
P = houghpeaks(H,100,'threshold',ceil(0.1*max(H(:))));
lines = houghlines(Ier,T,R,P);
%% plot
imshow(I);hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','blue');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
From here, you can start thinking on what to delete. This is not straightforward unless you have a dictionary of symbols, e.g. how do you delete the line around the structures with >-<
shape? do you delete all the middle pixels or do you keep the entire middle thin bar? You can only know this if you know how the symbol should be without the thick lines.
edited Nov 14 '18 at 11:39
answered Nov 14 '18 at 11:33
Ander BiguriAnder Biguri
26.3k105491
26.3k105491
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
add a comment |
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
I used Hough Lines transform but due to the thickness of black lines there were many small lines detected in one big line and it was difficult to control through the parameters. I have a few questions: 1) why erode with a disk element of size 1? 2) Why not erode with rectangular element? 3) The green line seems to pass over the symbols whereas in the input image black line never crosses any symbol, actually we have to consider them as line segments before and after any symbol. 4) are the blue cross beginning and red cross end of a single line? 5) one small segment in bottom was not detected.
– SKR
Nov 15 '18 at 5:21
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
@SKR 1)empirical test showed good result, didnt think of it more. 2) same as 1. 3) The last paragraph is about that. This is not a full solution to your huge project, just a starting point. Your question is too big to answer in SO entirely. People get paid to solve this type of problems. 4) yes, check the code 5) Yes
– Ander Biguri
Nov 15 '18 at 9:51
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%2f53294066%2fgeneral-approach-for-extracting-specific-lines-or-line-segments-in-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
The "thick black lines" you speak of... They appear to have a height or width that's higher than the other lines, yes?
– rayryeng
Nov 14 '18 at 7:21
3
You should look into Hough transformation - after erosion, it is probably possible to detect the straight lines left
– T A
Nov 14 '18 at 7:47
1
what about erosion, followed by lineSegmentDetector? The noise should hopefully not build up line segments?
– Micka
Nov 14 '18 at 7:49
4
An ideal solution as picture would be helpful, otherwise e.g. "thick horizontal line" is ambiguous.
– Vroomfondel
Nov 14 '18 at 9:45
1
I think the expected output would be desirable... Or else we are all going to propose solutions that may not be what you want. Please update your question to provide what the expected output is.
– rayryeng
Nov 14 '18 at 20:21