How to labeling the tip of the head and the end of the tail of this fish image? Like how i did with the center of the fish using centroid.
2 次查看(过去 30 天)
显示 更早的评论
Tommy
2014-7-16
i attach the image for reference if you do not understand. have problem putting a label on the head and tail.
采纳的回答
Image Analyst
2014-7-16
You didn't attach an image. You can use text() or plot() to label the ends.
47 个评论
Image Analyst
2014-7-18
So pick your marker and plot it. Say you want a * at (x,y):
plot(x, y, 'r*', 'MarkerSize', 10, 'LineWidth', 2);
Get the orientation, and majoraxislength to figure out your x,y using just basic trig or algebra like you learned in 10th grade. Remember the point slope formula of a line? Trivial. You'll have to figure out which end is thicker if you want to use different markers for head and tail. You could also use annotation() if you want to draw an arrow from tail to head.
Tommy
2014-7-18
yes, i used major and minor to get the x value but i don't get how to obtain the y value. In the end of all the plotting, i need to take the points and do a RMS deviation.
Image Analyst
2014-7-18
Like I said you need the orientation, which is the angle. Then take the arctangent to get the slope, then use the point slope formula. 10th grade stuff.
Image Analyst
2014-7-21
measurements = regionprops(labeledImage, 'MajorAxisLength', 'Orientation');
allAngles = [measurements.Orientation];
The point slope formula is
(y-yc) = slope * (x-xc)
where xc,yc is your centroid. You need to figure out x and y, which will be at the head and tail. So (xTail-xc)/2 = (MajorAxisLength/2) * cosd(angle). Does that give you enough to complete it?
Tommy
2014-7-23
Zebrafish_Majoraxislength = [Zebrafishdataa.MajorAxisLength]; Zebrafish_Minoraxislength = [Zebrafishdataa.MinorAxisLength]; Zebrafishtail = Zebrafish_centroid+[-Zebrafish_Majoraxislength/2,-148]; Zebrafishhead = Zebrafish_centroid+[+Zebrafish_Minoraxislength*1.5,73];
i did this which leaves a mark at the place. but i need the code to auto detect it like let say if the fish change position, will it auto detect its head and tail again?
Image Analyst
2014-7-23
Whatever you did to find the fish and produce a binary image of it, you will just do that same thing again. The process of putting markers at the head and tail is not dependent on what you do to get the binary image in the first place.
Tommy
2014-7-23
oh i see. i thought i could use the same code as to determine its position automatically. is there a way to do so? to find the head and tail automatically?
Image Analyst
2014-7-23
I thought you already had a way to identify the head and tail. One way to do it would be to put a circle around each endpoint of the line that we just discussed drawing. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F Then use the circle mask to sum up the number of binary white pixels in the mask. The end with the greater number will be the head and the end with the smaller number will be the tail.
Tommy
2014-7-24
i would like to ask if you know how to find the maximum and minimum area of the fish. Do you think using this method is better? Which will be able to auto detect the head(which is maximum) and tail(which is minimum) for different images of the same fish.
Image Analyst
2014-7-24
It sounds like you need a basic tutorial in image analysis, which is in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 The tutorial will show you how to get the binary image of your fish (which you already know), and then how to call regionprops to get the areas of all the fish. In short, it's something like
measurements = regionprops(labeledImage, 'Area');
allAreas = [measurements.Area];
[biggestArea, indexOfBiggest] = max(allAreas);
[smallesArea, indexOfSmallest] = min(allAreas);
That will give you the area of the biggest and smallest fish.
To find the areas at the head and tail, use the first two code sections in the FAQ to make circle masks at each endpoint of the line. Then count the pixels in the circle
% Get the count at one end of the fish.
circle1 = binaryImage & circleMask1; % Mask binary image by circle mask.
pixelsAtEndpoint1 = sum(circle1(:))
circle2 = binaryImage & circleMask2; % Mask binary image by circle mask.
pixelsAtEndpoint2 = sum(circle2(:))
if pixelsAtEndpoint1 > pixelsAtEndpoint2 then endpoint 1 is the head. Otherwise it's the tail.
Tommy
2014-7-25
i did a try on it but i realise i need to do it for every picture of my fish. IS there like a code to auto detect head & tail when i change picture like centroid?
Image Analyst
2014-7-25
编辑:Image Analyst
2014-7-25
Yes you will need to do it on every fish object in your image one at a time, but that should not be a problem - why do you hint that it is?
The Mathworks is still working on their automated Fish Head and Tail toolbox. Just kidding of course.
If this answers your questions, could you finally mark the Answer as Accepted?
Tommy
2014-7-29
it will be a problem as there will be thousand of pictures and i cant be doing it one by one. But anyway thanks for your help and patience.
Image Analyst
2014-7-29
Why not? It should take just a second or so per picture if there are, say, a dozen fish. So a thousand pictures takes 1000 seconds or 15-20 minutes. What's the problem with that? Some people have programs that run for days. Explain why you can't wait 20 minutes.
Tommy
2014-7-29
true but people now want automatic. Is actually the same fish but moving around in a cylinder. So 2-3 seconds will take picture of its movement. Then i got to calculate the movement of the fish. That is why i need 3 points of each picture, the head, the body and the tail. Centroid is for body. Head and tail i am still figuring out.
Image Analyst
2014-7-29
You imply that it's not automatic. Tell me what is not automatic about the process I described? There is no user-assisted steps in it where the user has to manually draw or indicate something on the image. Why do you imply that it is not "automatic"? Please define not automatic - your definition. Because as far as I see it, you just highlight all the images in a listbox and click the "Go!" button and it batch processes the whole batch of images with no further user interaction (unless you want to ask them for an Excel filename for any results).
Tommy
2014-7-29
编辑:Image Analyst
2014-7-29
as in automatic like every time change picture will detect the coordinates of head and tail. Now i using the pointers and to put at the end of the tip of the head and tail. Then using the position of the pointers for the coordinates for my equation.
%5th and 1st Head Difference
HeadDiff5 = (Zebrafishhead4 - Zebrafishhead).^2;
%5th and 1st Body Difference
BodyDiff5 = (Zebrafish_centroid4 - Zebrafish_centroid).^2;
%5th and 1st Tail Difference
TailDiff5 = (Zebrafishtail4 - Zebrafishtail).^2;
%RMSD result of 5th and 1st
E = ((HeadDiff5 + BodyDiff5 + TailDiff5)./3);
Result5 = sqrt(E);
For example like that. Where Zebrafishhead and Zebrafishtail are the pointers.
Zebrafishtail = Zebrafish_centroid+[-Zebrafish_Majoraxislength/1.83,-172];
Zebrafishhead = Zebrafish_centroid+[+Zebrafish_Minoraxislength*1.93,90];
So i am like trying to like get the position of the head and tail without writing those number(slowly putting the position of the marker). Like Major and Minor only can get the X value for the fish but not the Y value. I dont know how to use orientation for this. So if i can get the Y value of the Major and Minor it would be much easier for me.
Image Analyst
2014-7-29
I don't know what "using pointers" means, but you simply get a binary image like you already got, then use regionprops() to ask for centroid and orientation, and majorAxisLength of every fish. Then follow the steps I outlined to identify the two ends of the fish using those 3 measurements. Then place a circle mask over each end and determine which end is larger to identify the head. It's totally automatic.
Image Analyst
2014-7-30
Sorry, it's a bit more work that I would be willing to do for free. It's not like a 5 minutes job. I outlined the steps for you and I think you'll learn a lot by doing it yourself. See the Image Segmentation tutorial in my File Exchange if you need an example.
Tommy
2014-7-30
Alright thank you so much for helping me. I am gonna try using the point slope formula and then try using the circle mask too. By saying using the 2 sections from FAQ, you mean the 2 paragraph code right? Still trying to understand it step by step. Thanks anyway for your patience and help. Appreciate it a lot.
Image Analyst
2014-7-30
I was probably talking about the section that tells you how to create a circle mask and the one telling you how to batch process a sequence of files.
Tommy
2014-7-31
I finally understand the code you're trying to say. Do you know how to cut the image in half from the centroid vertically or horizontally?
Tommy
2014-7-31
i like to add on. I already found a past work of you drawing a line from the centroid vertically and horizontally. Is there a way to use the separated parts?
Image Analyst
2014-7-31
Yes you could but it's not as robust, and if the fish is aligned vertically you may not be able to tell which side is head and which side is tail. I suggest you use the circle mask method where you find the endpoints and place a circle mask over each endpoint and count the pixels.
Tommy
2014-8-1
oh, but can you explain how can i use the separated sides? if the fish is vertical, i can change the like to horizontal too.
Image Analyst
2014-8-1
That method is no easier than the method I suggested, and yet less robust, so I don't why you want to use it. You'd have to label the image (after splitting apart) then call regionprops and see which side is larger, but whether it is "right" or not depends on where you split it. It's possible that if you split it at the centroid that each half may have the same number of pixels. Not a problem with the method I outlined to you.
Tommy
2014-8-1
i know the steps to do it but i am like stuck. For the method you suggested, how do i get the endpoints? i know have to use centroid, orientation and majoraxislength to obtain it but i have no idea how. And i do not know how to put the circle inside. That's why if you are free, i hope you can write me a sample of it.
Image Analyst
2014-8-1
Maybe on the weekend if I have time. In the mean time, upload a binary image with at least two fish in it with no other stuff like blue pixels, lines, circles, text, axes, tick marks, white or gray surround, screenshots, or any other "stuff" - just the bare binary image.
Tommy
2014-8-1
Image Analyst
2014-8-1
Will you ever have two in one picture, or only part of one in the field of view?
Tommy
2014-8-4
thank you sir! i will read through and try the codes out and get back to you. i really appreciate your patience and time with me.
Tommy
2014-8-4
it works nicely. thank you sir. one question, what is the position for the centroid, head and tail?
Image Analyst
2014-8-4
If you want, you can change the last lines of code to be like this:
% Put a label at the head
if numWhitePixels2 > numWhitePixels1
text(x(index2), y(index2), 'Point 2 = Head', 'FontSize', fontSize, 'Color', 'r');
text(x(index1), y(index1), 'Point 1 = Tail', 'FontSize', fontSize, 'Color', 'r');
xHead = x(index2);
yHead = y(index2);
xTail = x(index1);
yTail = y(index1);
else
text(x(index1), y(index1), 'Point 1 = Head', 'FontSize', fontSize, 'Color', 'r');
text(x(index2), y(index2), 'Point 2 = Tail', 'FontSize', fontSize, 'Color', 'r');
xHead = x(index1);
yHead = y(index1);
xTail = x(index2);
yTail = y(index2);
end
This will make variables xHead, xTail, yHead, and yTail.
Tommy
2014-8-5
alright, thank you sir. erm do you know how to plot a x-graph and y-graph? like value against x or value against y.
Image Analyst
2014-8-5
Not sure I understand your question. I don't know what "erm" means and I'm sure you've heard of the plot() function, so I don't know what to say.
Image Analyst
2014-8-7
You aren't still splitting your fish down the middle are you? And what's with that line along the left column that I had to delete? Other than that I don't know what you're talking about so post a screenshot.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
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 (한국어)