Help regarding Image Segmentation of B/W Image!!
2 次查看(过去 30 天)
显示 更早的评论
Hello! I am working on a project titled 'Yarn Hairiness determination using Image Processing'. The steps involved are- Image processing and Image analysis. In the processing, I converted the image to B/W. After that I am suppose to segment the core yarn from the its protruding fibres. I am stuck here. I have attached the the picture below. It would be a big help!
5 个评论
Image Analyst
2015-3-14
编辑:Image Analyst
2015-3-14
Please attach the image so we can help you. Maybe you forgot to click "Attach file" after you browsed to the image??? Better yet, just use the brown and green frame icon to insert the image into the body of your message.
Samkit Mutta
2015-3-20
The above posted are two different images. Please do take a look and reply ASAP!
Image Analyst
2015-3-20
Yes, they do look different: different color, different fiber composition, different amounts of fray, different thread diameter, etc. Exactly what do you want to characterize in the two images?
Samkit Mutta
2015-3-23
Herein, I need to find out- 1. the diameter of the core of the yarn. 2. the length of the protruding fibres(if not possible then number of protruding fibres in the visible segment of the yarn.
采纳的回答
Image Analyst
2015-3-27
Alright, I did a full blown demo for you. It sues activecontour() to smooth the main thread bulk. See attached m-file below the images.
Be sure to change the folder name and file names in the script.
15 个评论
Samkit Mutta
2015-3-29
Sir you have done me a huge favour by helping me with the processing part of the image. I am highly obliged looking at your efforts. The code is lengthy and it might take some time for me to get thorough with and to understand the whole of it. However, I ran the code and it worked properly. A correction- 'line 107'-you should remove the argument 'smooth factor' because it creates an error. I remember using active contour once but it turned out very poor and not even remotely close to yours! I''l scope through it and let you know if any doubts. Once again, thanks!
Samkit Mutta
2015-3-29
The thickness of the core of yarn is irregular. Can it be made more smooth by increasing the number of iterations? Also I need to find the Average Diameter of the core. How do I do that?
Image Analyst
2015-3-29
Samkit, perhaps SmoothFactor is a new option. I have release R2015a - what do you have? To get the average thickness, just get the area and divide by the length. It looks like it doesn't quit include the left and right column so you might have to find the length
verticalProfile = sum(binaryImage, 1);
leftColumn = find(verticalProfile, 1, 'first');
rightColumn = find(verticalProfile, 1, 'last');
yarnLength = rightColumn - leftColumn + 1;
area = sum(binaryImage(:));
averageWidth = area / yarnLength;
Samkit Mutta
2015-3-29
I am using R2014a. Might be that's why it doesn't accept SmoothFactor. I'm sorry I did not understand the line of yours- 'It looks like it doesn't quit include the left and right column so you might have to find the length' And where should I include this extra code exactly?
Image Analyst
2015-3-29
It looked like the right and left column were black, but maybe that's just the outer outline of the axes control. There is no extra code - that's all the code. It will work for all cases, regardless of whether the fiber goes all the way to the first and last column.
Samkit Mutta
2015-4-11
I'm very sorry for replying so late to you. I have been stuck up with the formalities of this project. What I want to know is that the where should I put the code( which you provided above for diameter) in the main matlab file "test.m". Is it going to be in continuity with the main program?
I also have to find the hairiness index(it is the ratio of the length of the fibres to the length of the core). It seemed too difficult for me to try that even with the help of my guide. The main problem I am facing there is that since the fibres are highly twisted and intertwined amongst each other, I am very far from calculating the length of the fibres.
Image Analyst
2015-4-11
You can't get the length. They could be overlapping and they could be pointing towards the camera. The best you can do is the area fraction - the ratio of the area of the fuzz to the area of the main thread. You have everything to do that.
Samkit Mutta
2015-4-14
Yes. I completely agree about your view on the finding the length. All I need to do is work on the the area fraction. One thing- What should I alter if I want to make the 'initial mask' more smooth. e.g. 'The image with name 'binary main, bulk thread' has a lot of unevenness. How can I make it smoother? Also on running the program there is an overlapping of the image titles "final outer boundary mask using 500 iterations" and "Image with initial and final counter overlaid". How to distinguish them?
Image Analyst
2015-4-18
Sorry - I didn't know my assignment was due in 3 days. I guess I'll try to adjust the parameters to activecontour, like "smoothness" to make it more smooth. And I guess I could use text() to put up a label/legend that the blue contour is the initial and the red is the final. I thought it was kind of obvious because the red one really hugs the fiber whereas the blue one is really coarse and crude and approximate, but I guess it's not obvious to everyone. Is there a link at your university where I'm supposed to upload my final submission?
Samkit Mutta
2015-4-18
编辑:Samkit Mutta
2015-4-18
Here are the various fields where some changes might be needed. I'll mention them in pointers- 1. Figure 1- specifying the contours isn't necessary. Because I'll use only the final contour. What I meant to say was that the subplot(3,3,7) and subplot(3,3,8) were having overlapped titles; which I solved by changing subplot(3,3,8) to subplot(3,3,9). 2. Figure 2- No changes needed. 3. Area Dialogue box- No changes needed.
Regarding the working of code- 1. As you said about working on the smoothness, I'll work on it too! Because smoothening the image will make the 'Initial mask' more even. This will give us more accurate reading of the core diameter.
I myself am going to work on the area fraction code.
But for reference sake I need you to Please send me the final code file with the Diameter's code as well as the "Area Fraction" code in it.
This code will be the one which I will present finally to the Examiner.
There is no web-link to post the work. You'll have to send me the work which, I later on will present to the External Examiners.
It will be great if you can look into a reference paper which my team has been looking upto. I've attached the file below.
If there is anything I can do to assist you then please command! :D
Image Analyst
2015-4-18
For area fraction, there is nothing to "work on" - it's just a single line of code:
areaFraction = sum(binaryImage(:))/numel(binaryImage);
Maybe I should just come over. We can work on it and then Monday we'll present my code to your External Examiners together. What is your address?
Himalaya Jain
2015-4-18
Hey this is one of the team mate of samkit mutta. We would like you to help us by sending the complete code for our topic assap. One more thing to ask, the code that u provided for the diameter, when i had merged it with the code that you had provided earlier, there were lots of error popping. And i was not able to distinguish which line to work on to clear the errors. So i would like you to please see to this also.
Image Analyst
2015-4-18
Go ahead and post your merged code, along with the specific image that it's failing on. Chances are that you are not using the correct variable names.
Samkit Mutta
2015-4-19
Hahaha! I get your sarcasm. Even I know that it's a single line of code. What I meant to say was that I'll have to present that in the program as well as my submission material because till now we were under the impression that we can be able to find the hair length. And now thats not possible! However we'll get back to you today with if any difficulties.
更多回答(3 个)
Meghana Dinesh
2015-3-20
Try using the Morphological operators dilation and erosion.
4 个评论
Samkit Mutta
2015-3-23
I tried erosion but unfortunately the thickness of the yarn gets reduced. Also, i need to change the parameters in the code time and again.
Meghana Dinesh
2015-3-27
Maybe you can use spur and then subtract the Images (before and after spur) and improve on this to get your second requirement.
Samkit Mutta
2015-3-29
I tried the functions you mentioned before and now again, and it does not work. I guess the problem is because it can distinguish between the fibres and the core.
Image Analyst
2015-3-23
Simply try thresholding. See my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 You might also like my demo for how to extract the largest blob, attached.
Samkit Mutta
2015-4-19
@Image Analyst- Whenever I run the "test.m" file, the workspace stays empty. It never used to happen before. I get workspaces for all the scripts but i do not get it any functions file. Please help!
26 个评论
Image Analyst
2015-4-19
That's the way MATLAB works. If you run a script, you put variables into the base workspace. Each function has it's own private workspace that comes into existence when you enter the function and goes away when you leave the functions. I'm sure you've heard of "garbage collection" in java. So to see any variables in a function, you have to set a breakpoint in that function. The reason I did a function instead of a script was that I could then put all the functions in the same m-file. You can't have a script followed by a function in the same m-file so if I had a script, I would have to have had at least two m-files, not one.
Samkit Mutta
2015-4-19
Yeah. I got a bit familiar with how the way scripts and functions work. But now even if run any functions file, workspace wont show up. How am I suppose to get it working? Coz after adding the diameter and area fraction code, I really need the workspace to get the values
Image Analyst
2015-4-19
Put this line of code into your code:
workspace; % Make sure the workspace panel is showing.
Samkit Mutta
2015-4-19
It's already there! It's the one you put in your code! I have extended the same code.
Image Analyst
2015-4-19
Then why do you say the workspace does not show up? Put a breakpoint on that line of code and see if the workspace panel shows up when you execute the line of code. And if it does, step through the code to see when the workspace panel vanishes. Of course if you step out of a function, the workspace panel will now show the parent routine's variables, but the panel should still be there.
Samkit Mutta
2015-4-20
I'm so sorry for giving the wrong info. What I meant to say was that the workspace shows up but its empty always. No variables. This happens with all functions file
Image Analyst
2015-4-20
Are you sure you don't have a "clear" or "clear all" or "clearvars" in there somewhere?
Samkit Mutta
2015-4-20
Yes I don't have any words like that. It's the same code which you have provided me. I have completed the coding part. I'll send you the code. Please have a look and revert back.
Image Analyst
2015-4-21
I don't have that problem. I set a breakpoint there and, and you can see in the screen capture below, you can clearly see the workspace panel on the left with the variables showing up inside it. If you don't see that, call the Mathworks.
Samkit Mutta
2015-4-21
I set a breakpoint at the line "message=sprintf......" that is just before the line of dialogue box. This gave all the variables in the workspace like it used to give when you first sent me the 'test.m' file. So tell me whether there was any breakpoint set in the original code you sent? If yes then please tell me where did you put it.
Image Analyst
2015-4-21
I did not set any breakpoints. I just let the code run uninterrupted. So the workspaces popped into being while the function was being executed, and vanished when the functions exited, just like they're supposed to. You can't see the workspaces while the function is executing with no breakpoints - it simply doesn't need to display them because it doesn't need to since there's no way you could examine them anyway. You can only see and examine the workspace variables when you have set a breakpoint and stopped at it.
Samkit Mutta
2015-4-21
Finally now I understand it. Since long I was under the impression that I might have changed something accidentally and because of that I could not see any variables in the workspace. Now that you have explained that this is the way it has been made, I feel a sigh of relief!
I have created a final, ready-to-submit file. I am uploading it. Go through and please reply.
Samkit Mutta
2015-4-21
This might be the last favour I would ask. As you see from the end dialogue box, we get a value called 'Hair Area Index' (H.A.I). What I plan on doing is inserting a 'input dialogue box' using 'inputdlg' function which will ask the user for the value of hair area index. And then we can compare the value with the one we obtain in our dialogue box. If the obtained value of H.A.I is more than the user entered value then the yarn quality is will be considered unacceptable and the opp. for good.
Image Analyst
2015-4-22
Here's a snippet on inputdlg():
% Ask user for two floating point numbers.
defaultValue = {'45', '67'};
titleBar = 'Enter a value';
userPrompt = {'Enter number 1 : ', 'Enter number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check for a valid integer.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
usersValue = defaultValue;
message = sprintf('I said it had to be a number.\nI will use %f and continue.', usersValue1);
uiwait(warndlg(message));
end
and I'm sure you know how to use and "if" statement to compare numbers.
Samkit Mutta
2015-4-23
编辑:Samkit Mutta
2015-4-23
I am weak in the c++ coding. So help me here. This is what I came up with-
prompt={'Enter Hair Area Index'};
dlg_title='Input';
answer = inputdlg(prompt,dlg_title)
if answer <= hairareaindex
disp('Yarn Quality Acceptable')
else
disp('Yarn Quality unacceptable')
end
But I get an error at line 'if answer <= hairareaindex'
Image Analyst
2015-4-23
Try this:
hairareaindex = .5; % The ACTUAL hair index.
% Ask user for hte acceptable value.
prompt={'Enter the acceptable Hair Area Index'};
dlg_title='Input';
userResponse = inputdlg(prompt,dlg_title)
acceptableHairIndex = str2double(cell2mat(userResponse))
if acceptableHairIndex <= hairareaindex
message = sprintf('The actual hair index of %f is above the acceptable value of %f, so this yarn IS Acceptable',...
hairareaindex, acceptableHairIndex);
uiwait(msgbox(message));
else
message = sprintf('The actual hair index of %f is below the acceptable value of %f, so this yarn IS NOT Acceptable',...
hairareaindex, acceptableHairIndex);
uiwait(warndlg(message));
end
Samkit Mutta
2015-4-27
so all I forgot to implement was the string to double function. Once I did that it was all smooth. I also applied the same logic for another input dialogue box in this code.
Finally the whole code is complete and submitted.
The examiners really liked the topic of project and were impressed by the result we had to offer.
Samkit Mutta
2015-4-27
Hey! I would really like to thank you a tons for helping me out in this project. This couldn't have worked much if you hadn't helped me. Your helpful attitude is appreciated. I was very much surprised when I first opened the "test.m" file you initially sent. I couldn't have thought that I would get help so easily. Thanks again!
Image Analyst
2015-4-27
You're welcome. I'm glad I could help you towards a successful project. If you want, you can also "Vote" for my two answers to give me "reputation points".
sudha muthusamy
2018-7-14
image analyst sir, i am also doing same sort of project ,can u help me to work this in 3d yarn image .
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)