You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to draw lines on some part of defect segmented image.
1 view (last 30 days)
Show older comments
Hi, I want to draw two lines on image automatically. For your reference I have drawn those lines manually marked with green and violet colors using imline function as shown in matlab. Can anyone help me in this. Any help is much appreciated!!![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/611405/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/611405/image.png)
19 Comments
DGM
on 8 May 2021
If you're using imline(), why not just ... use imline()? If you can calculate the extents of the line, just specify them:
% H = imline(HPARENT,X,Y) creates a draggable, resizable line on the
% object specified by HPARENT. X and Y specify the initial endpoint
% positions of the line in the form X = [X1 X2], Y =[Y1 Y2].
If you don't know the extents (X, Y), then how to find them depends entirely on your unstated goals.
Image Analyst
on 8 May 2021
There are millions of pixels in the image. How are you "automatically" going to define the endpoints of a line segment? I see no rationale for why you picked the location of the endpoints that you chose. Can you describe in words what an algorithm would to to automatically find those points?
Do you want the lines IN the image (burned into the image pixels) or do you want do draw a line segment in the overlay above the image?
kanika bhalla
on 10 May 2021
Hi DGM, Thank you so much for your reply.
H = imline(HPARENT,X,Y)- This is totally manually. I have to manually calculate the X = [X1 X2], Y =[Y1 Y2] coordinates. That is not practical for my objective. Actually I am working on a industrial AOI defect detection project. We need to automatically draw lines for the laser cutting. Could you share more ideas with me.
Thank you very much!!
kanika bhalla
on 10 May 2021
Hi Image Analyst, Thank you very much for your reply.
"Automatically" defining of the endpoints of a line segment is challanging for me. I have picked the location of the endpoints that you chose because this defect is present on thev dataline which will lead to short circuit. Therefore the chosen points are the dataline points. I am working on the industrial project where we need to do laser cutting. Even I have no clue how I am going to do this automatically. If you can share any ideas. It would be helpful for me.
Thank you!!!
DGM
on 19 May 2021
If you're trying to do something like that, then perhaps the defect itself does not contain information relevant to further processing; after all, it's a defect. We have no idea how you're identifying the defect or what the surrounding area looks like. You may need to use information derived either from the surroundings or from knowledge of the expected object structure.
kanika bhalla
on 19 May 2021
Hi @DGM
Thank you very much for your answer.
Even I am not sure how to proceed further. Is there any way to seperate the colors and draw lines over it. As where i need to draw line is having different color from the other part. Can you share some functions to proceed further.
Thank you for your help!!
DGM
on 19 May 2021
Edited: DGM
on 19 May 2021
I think at this point, we need a description of how you're identifying the defects, as well as some examples of the images being processed (if that's possible). I'm hardly an expert at this, so I tend to not have preformulated approaches to these things.
I imagine a starting point would be to determine the desired structures which intersect the defect and then determine how they should continue (or the inverse). That may not be very robust depending on how large the defects might be and whether the defects obscure features (like corners) which may confuse simple approaches.
kanika bhalla
on 20 May 2021
Hi @DGM
Thank you very much for your help!!!
I have checked the link but my problem didn't get solve.
Thanks for introducing me with new concept of houghlines.
Image Analyst
on 20 May 2021
Again, I have no idea where you drew any lines on that multicolored blob. I don't see violet and green lines. How about if I drew a line from (100,100) to (120, 150) -- would that work for you? If not, why not. I could draw a line between those coordinates completely automatically, with no interactive user involvement at all, as long as I knew then end points. If the endpoints of (100,100) and (120,150) don't work for you then explain in excrutiating detail why they don't work for you.
DGM
on 20 May 2021
Let me illustrate the problem. Let's say we have some line features and a defect:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623733/image.jpeg)
You can extract the defect alone:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623738/image.jpeg)
But note that the defect doesn't contain any information about where the lines are supposed to be. The surroundings might:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623743/image.jpeg)
So maybe that information could be used.
However, that information alone is potentially insufficient to solve the problem (or at least not without a lot of work). What if your routine finds something like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623748/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623753/image.jpeg)
Would a simple routine that projects straight lines be able to figure that out correctly? What about this?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623758/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623763/image.jpeg)
Of course, I still don't know what your images look like, so I'm just guessing at what difficulties might arise.
kanika bhalla
on 20 May 2021
Thank you very much @DGM for further illustrating about the possible solutions to the problem. I want to discuss further on this. As the 2nd image posted by you is the same as what i obtained as shown above in this post. After that 3rd picture posted by you can be done in my case too. But how to obtain third picture and how it can be further used to mark lines.
I am attaching my original image from which I have obtained segmneted defect.
Could you please further guide me how I can proceed further to achieve my goal. Thank you so much for your time and
help!!!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623773/image.jpeg)
kanika bhalla
on 20 May 2021
The lines were drawn manually on the blob using imline function. Violet and green lines are drawn on the blob as shown in the figure with pointed ends (imline function). As instructed by you to draw lines by giving coordinates. It will work and easily draw a line but this is manually done. As user is manually giving points. My task is to determine these points or coordinates automatically. I need to make 2 lines automatically as shown in the attached figure. Is there anyway to determine these coordinates automatically by some methods.
This is because defect is present on the green data lines and i need to do laser cutting from those lines. This will work as a path for laser cutting. Hope now description of the problem is clear. Thank you for your time and help!!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623783/image.png)
Image Analyst
on 20 May 2021
So you want code to have the user manually draw a line and return the endpoints so you can draw a line? How about imline(), drawline(), or improfile(). Those all should do it.
If you don't want the user to manually draw anything, then say what they are taking into consideration when they are drawing lines. Otherwise how will I know where to draw them. Like the color gradient in the image or whatever. Like why was the purple line drawn there and not at a location shifted 20 pixels downward???
Post the original image that the user draws on, without the lines drawn/burned into it.
kanika bhalla
on 20 May 2021
Edited: kanika bhalla
on 20 May 2021
No I don't want anything user to manually draw a line and return the endpoints so you can draw a line. I want to get the end points to draw line automatically. I have drawn those violet and green lines using imline function only. And drawline(), or improfile() won't solve my problem.
Yes I don't want the user to manually draw anything, that is why I want help or some ideas what can be taken into considereation from that defect part to draw lines. Like if there is any method or way I can get the coordinates of the image as my defect part is on white background. Is there any way that code will give coordinates where it will find value except 255.
The purple line drawn there and not at a location shifted 20 pixels downward because I am working on the industrial project of the automated inspection of the panel images. And the defect was present on the green data lines which will lead to short circuit. So, our task is basically to seperate the defect present on the green data lines. Therefore I need to draw lines only on green part so that i will generate a path for the laser cutting.
Here I have attached the original panel image, defect seperated from the panel image and I have already posted above the image where i have manually drawn the violet and red lines which should be done automatically rather than any user interaction. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623948/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/623948/image.jpeg)
Image Analyst
on 21 May 2021
Probably not. It took you two weeks to finally describe the situation and that wasted a lot of time. Today I'm preparing for a week long trip and won't have much time. Plus finding defect blobs like that in an abritrary colored image would be very hard and take a lot of time, time that I can't afford to spend/donate for you. Maybe someone else will spend the time. Sorry.
kanika bhalla
on 30 May 2021
Edited: kanika bhalla
on 31 May 2021
Helo Sir @Kalyan Acharjya Thank you so much for your reply. No Sir, I am still struggling a lot to solve the problem. Please help if you can. I will be forever grateful to you. Thank you!
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)