MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: Measuring object width in an image, thanks

 Subject: Measuring object width in an image, thanks From: Digistar You Date: 9 Aug, 2012 08:10:14 Message: 1 of 14 Dear all, I have a problem expecting good ideas. As you can see from the image (http://farm9.staticflickr.com/8298/7745154244_9b28e31afa_c.jpg), I want to measure the diameter of the cylinder in the image. My idea is to measure the distance between the two ending points of the red curve in the white rectangle. Please note that there was no the while rectangle in an original image. So, how can I measure the distance between the two ending points from the image? Any ideas are highly appreciated, thank you very much.
 Subject: Measuring object width in an image, thanks From: Image Analyst Date: 9 Aug, 2012 11:32:14 Message: 2 of 14 How about using improfile to let the user pick it interactively?
 Subject: Measuring object width in an image, thanks From: Digistar You Date: 9 Aug, 2012 12:59:13 Message: 3 of 14 Thanks a lot, but that is not possible. The project needs the algorithm to run automatically. "Image Analyst" wrote in message ... > How about using improfile to let the user pick it interactively?
 Subject: Measuring object width in an image, thanks From: Digistar You Date: 10 Aug, 2012 06:40:23 Message: 4 of 14 Can somebody help me? Thanks a lot. "Digistar You" wrote in message ... > Dear all, > > I have a problem expecting good ideas. As you can see from the image (http://farm9.staticflickr.com/8298/7745154244_9b28e31afa_c.jpg), I want to measure the diameter of the cylinder in the image. My idea is to measure the distance between the two ending points of the red curve in the white rectangle. Please note that there was no the while rectangle in an original image. So, how can I measure the distance between the two ending points from the image? > > Any ideas are highly appreciated, thank you very much.
 Subject: Measuring object width in an image, thanks From: Digistar You Date: 10 Aug, 2012 14:34:16 Message: 5 of 14 Ask for help again, :) "Digistar You" wrote in message ... > Dear all, > > I have a problem expecting good ideas. As you can see from the image (http://farm9.staticflickr.com/8298/7745154244_9b28e31afa_c.jpg), I want to measure the diameter of the cylinder in the image. My idea is to measure the distance between the two ending points of the red curve in the white rectangle. Please note that there was no the while rectangle in an original image. So, how can I measure the distance between the two ending points from the image? > > Any ideas are highly appreciated, thank you very much.
 Subject: Measuring object width in an image, thanks From: Image Analyst Date: 11 Aug, 2012 00:47:07 Message: 6 of 14 Why not just mask out stuff known not to be part of the cylinder, then sum vertically to get the average profile, then threshold to find where the edge of the cylinder starts and stops. Should be very easy. Can you upload the original image (without the white box)?
 Subject: Measuring object width in an image, thanks From: Digistar You Date: 13 Aug, 2012 07:38:06 Message: 7 of 14 I think the problem lies in that non-cylinder is not easily detected. I have uploaded an original image (http://farm9.staticflickr.com/8431/7771948574_6eca7b0741_k.jpg). Do you have any ideas how to measure the diameter of the cylinder? Thank you so much. "Image Analyst" wrote in message ... > Why not just mask out stuff known not to be part of the cylinder, then sum vertically to get the average profile, then threshold to find where the edge of the cylinder starts and stops. Should be very easy. Can you upload the original image (without the white box)?
 Subject: Measuring object width in an image, thanks From: Matt J Date: 13 Aug, 2012 09:44:06 Message: 8 of 14 "Digistar You" wrote in message ... > I think the problem lies in that non-cylinder is not easily detected. I have uploaded an original image (http://farm9.staticflickr.com/8431/7771948574_6eca7b0741_k.jpg). ============== The non-cylinder feature seems to always consist of a bright narrow band perpendicular to the cylinder. You could use RADON to detect and then exclude it. There should be a spike in the radon projection view whose rays are parallel to the band. Once you've found the band, you also have info about the tilt of the cylinder (if it is indeed always perpendicular to the band) and can get a more exact version of the average profile that ImageAnalyst was talking about. The average profile will be in the projection view 90 degrees from the one where the band spikes.
 Subject: Measuring object width in an image, thanks From: Digistar You Date: 13 Aug, 2012 10:47:06 Message: 9 of 14 Thanks Matt for the ideas. However, in my project, the problem is that the ends of the narrow red bands do not already match the edges of the cylinder. For example, I have uploaded another image (http://farm9.staticflickr.com/8296/7772735060_57e3bffcc3_k.jpg). Thus, it seems I have to detect the red narrow band in the middle first, and then try to measure its diameter. This seems to be not very easy. Do you have any suggestions? Thanks a lot. "Matt J" wrote in message ... > "Digistar You" wrote in message ... > > I think the problem lies in that non-cylinder is not easily detected. I have uploaded an original image (http://farm9.staticflickr.com/8431/7771948574_6eca7b0741_k.jpg). > ============== > > The non-cylinder feature seems to always consist of a bright narrow band perpendicular to the cylinder. You could use RADON to detect and then exclude it. There should be a spike in the radon projection view whose rays are parallel to the band. > > Once you've found the band, you also have info about the tilt of the cylinder (if it is indeed always perpendicular to the band) and can get a more exact version of the average profile that ImageAnalyst was talking about. The average profile will be in the projection view 90 degrees from the one where the band spikes.
 Subject: Measuring object width in an image, thanks From: Matt J Date: 13 Aug, 2012 13:47:09 Message: 10 of 14 "Digistar You" wrote in message ... > Thanks Matt for the ideas. However, in my project, the problem is that the ends of the narrow red bands do not already match the edges of the cylinder. For example, I have uploaded another image (http://farm9.staticflickr.com/8296/7772735060_57e3bffcc3_k.jpg). Thus, it seems I have to detect the red narrow band in the middle first, and then try to measure its diameter. This seems to be not very easy. Do you have any suggestions? Thanks a lot. ================ That doesn't seem relevant. Even in this new image, it looks like the radon projections of the bands will still spike strongly along rays perpendicular to the cylinder. You should be able to find the long background band easily and maybe even the smaller band defining the diameter of the cylinder (it always seems to to be the 2nd most intense band).
 Subject: Measuring object width in an image, thanks From: ImageAnalyst Date: 13 Aug, 2012 23:32:10 Message: 11 of 14 I agree with Matt. Actually this image looks even easier than your first one because there is far less clutter. It looks like a laser beam coming up at an angle and hitting a rod/shaft/cylinder so you should be able to narrow down the position somewhat, due to a known range of diameters, and just crop out that portion, making the alignment and profiling even easier.
 Subject: Measuring object width in an image, thanks From: Matt J Date: 14 Aug, 2012 15:38:06 Message: 13 of 14 "Digistar You" wrote in message ... > > According to the result (peak point at theta=89 degrees), I know the tilt of the red bands, based on which I may calculate the average profile later based on ImageAnalyst's suggestion. ============== RADON tells you more than this. The horizontal coordinate of the bright peak tells you that the band is tilted by 89 degrees. The vertical coordinate tells you the perpendicular distance (in pixels) of the band from the center of the image. Based on the figure you posted, it looks like the band is something like 150 pixels from the center? Another thing you could do is use IMROTATE to correct for the 89 degree tilt and make the cylinder perfectly vertical. Then if you do [~,rownum]=max(sum(image>0,2)); the resulting rownum should be the row number where the bright band approximately lies.
 Subject: Measuring object width in an image, thanks From: Digistar You Date: 15 Aug, 2012 15:31:14 Message: 14 of 14 Dear Matt, thank you so much for your time and detailed explanations. Now I completely understand your suggestions. I have also tested the algorithm on a few simple images, which works well. I will see if it works with more complex images. Thank you very much. Also many thanks to ImageAnalyst! "Matt J" wrote in message ... > "Digistar You" wrote in message ... > > > > According to the result (peak point at theta=89 degrees), I know the tilt of the red bands, based on which I may calculate the average profile later based on ImageAnalyst's suggestion. > ============== > > RADON tells you more than this. The horizontal coordinate of the bright peak tells you that the band is tilted by 89 degrees. The vertical coordinate tells you the perpendicular distance (in pixels) of the band from the center of the image. Based on the figure you posted, it looks like the band is something like 150 pixels from the center? > > Another thing you could do is use IMROTATE to correct for the 89 degree tilt and make the cylinder perfectly vertical. Then if you do > > [~,rownum]=max(sum(image>0,2)); > > the resulting rownum should be the row number where the bright band approximately lies.