<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221</link>
    <title>MATLAB Central Newsreader - Detecting spots on a butterfly</title>
    <description>Feed for thread: Detecting spots on a butterfly</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 03 Apr 2009 08:14:02 -0400</pubDate>
      <title>Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#639942</link>
      <author>Husam Aldahiyat</author>
      <description>Hello,&lt;br&gt;
Say I have a picture of a butterfly with black spots on its wings, what is a good way to create an algorithm that takes the picture as input and give the location and/or number of spots as output?&lt;br&gt;
The spots aren't circular.</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 11:33:01 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#639985</link>
      <author>Image Analyst</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gr4gga$d84$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; Say I have a picture of a butterfly with black spots on its wings, what is a good way to create an algorithm that takes the picture as input and give the location and/or number of spots as output?&lt;br&gt;
&amp;gt; The spots aren't circular.&lt;br&gt;
------------------------------------------------------------------&lt;br&gt;
Say you posted it somewhere.  Do you think you might get better answers?&lt;br&gt;
All I can say at this point is to try something like watershed segmentation, or an edge detector (such as Sobel) followed by a morphological closing operation.  You'll also need bwlabel and regionprops in the image processing toolbox.&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 11:47:01 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#639989</link>
      <author>Husam Aldahiyat</author>
      <description>&quot;Image Analyst&quot; &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;gr4s5d$3lf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gr4gga$d84$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; Say I have a picture of a butterfly with black spots on its wings, what is a good way to create an algorithm that takes the picture as input and give the location and/or number of spots as output?&lt;br&gt;
&amp;gt; &amp;gt; The spots aren't circular.&lt;br&gt;
&amp;gt; ------------------------------------------------------------------&lt;br&gt;
&amp;gt; Say you posted it somewhere.  Do you think you might get better answers?&lt;br&gt;
&amp;gt; All I can say at this point is to try something like watershed segmentation, or an edge detector (such as Sobel) followed by a morphological closing operation.  You'll also need bwlabel and regionprops in the image processing toolbox.&lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; ImageAnalyst&lt;br&gt;
&lt;br&gt;
The pictures are like this one:&lt;br&gt;
&lt;a href=&quot;http://img8.imageshack.us/img8/1272/200903153435.jpg&quot;&gt;http://img8.imageshack.us/img8/1272/200903153435.jpg&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
I've read the help and tried some things but still having trouble.</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 12:09:01 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#639993</link>
      <author>Husam Aldahiyat</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gr4svl$paf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Image Analyst&quot; &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;gr4s5d$3lf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gr4gga$d84$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hello,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Say I have a picture of a butterfly with black spots on its wings, what is a good way to create an algorithm that takes the picture as input and give the location and/or number of spots as output?&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; The spots aren't circular.&lt;br&gt;
&amp;gt; &amp;gt; ------------------------------------------------------------------&lt;br&gt;
&amp;gt; &amp;gt; Say you posted it somewhere.  Do you think you might get better answers?&lt;br&gt;
&amp;gt; &amp;gt; All I can say at this point is to try something like watershed segmentation, or an edge detector (such as Sobel) followed by a morphological closing operation.  You'll also need bwlabel and regionprops in the image processing toolbox.&lt;br&gt;
&amp;gt; &amp;gt; Regards,&lt;br&gt;
&amp;gt; &amp;gt; ImageAnalyst&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The pictures are like this one:&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://img8.imageshack.us/img8/1272/200903153435.jpg&quot;&gt;http://img8.imageshack.us/img8/1272/200903153435.jpg&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I've read the help and tried some things but still having trouble.&lt;br&gt;
&lt;br&gt;
I'm not well versed in the IPT but the thresholds I impose count the spot as one part with the wing. &lt;br&gt;
Any help is appreciated.</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 12:30:03 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#640004</link>
      <author>Husam Aldahiyat</author>
      <description>Here is my progress so far:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; I=imread('2009_03_15_3434.JPG');&lt;br&gt;
&amp;gt;&amp;gt; I=rgb2gray(I);&lt;br&gt;
&amp;gt;&amp;gt; bw = im2bw(I,.3);&lt;br&gt;
&amp;gt;&amp;gt; bw = bwareaopen(bw,30);&lt;br&gt;
&amp;gt;&amp;gt; imshow(bw)&lt;br&gt;
&lt;br&gt;
I want to use regionprops() like in one of the demos and decide which objects are more round, which will be the spots. But how can I split my pic into objects???</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 12:47:01 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#640005</link>
      <author>Husam Aldahiyat</author>
      <description>&quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gr4vgb$5sn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Here is my progress so far:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; I=imread('2009_03_15_3434.JPG');&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; I=rgb2gray(I);&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; bw = im2bw(I,.3);&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; bw = bwareaopen(bw,30);&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; imshow(bw)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to use regionprops() like in one of the demos and decide which objects are more round, which will be the spots. But how can I split my pic into objects???&lt;br&gt;
&lt;br&gt;
I solved the problem finally. The problem was I needed to do bw=~bw :)</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 14:29:57 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#640043</link>
      <author>Skeptic</author>
      <description>&lt;br&gt;
&lt;br&gt;
Husam Aldahiyat wrote:&lt;br&gt;
&amp;gt; &quot;Husam Aldahiyat&quot; &amp;lt;numandina@gmail.com&amp;gt; wrote in message &amp;lt;gr4vgb$5sn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Here is my progress so far:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&amp;gt; I=imread('2009_03_15_3434.JPG');&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&amp;gt; I=rgb2gray(I);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&amp;gt; bw = im2bw(I,.3);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&amp;gt; bw = bwareaopen(bw,30);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&amp;gt; imshow(bw)&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I want to use regionprops() like in one of the demos and decide which objects are more round, which will be the spots. But how can I split my pic into objects???&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I solved the problem finally. The problem was I needed to do bw=~bw :)&lt;br&gt;
--------------------------------------------------------------&lt;br&gt;
Good.  To decide on roundness (circularity) just use the compactness&lt;br&gt;
measure from regionprops or just look at the perimeter^2 to area&lt;br&gt;
ratio.  Thresholding the red or green channel will get you the brown&lt;br&gt;
spots on yellow background pretty easily (better than using im2bw&lt;br&gt;
which will include the blue channel which you probably don't want).&lt;br&gt;
To get the orange spots on orange background - well that's pretty&lt;br&gt;
tough.  Might try hough transform or edge filters or ask Dave&lt;br&gt;
Robinson's opinion or ask over in sci.image.processing.  If you get&lt;br&gt;
something, you can post the code and see if I can improve on it's&lt;br&gt;
performance.&lt;br&gt;
Good luck,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 19:31:53 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#640130</link>
      <author>Walter Roberson</author>
      <description>Husam Aldahiyat wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; Say I have a picture of a butterfly with black spots on its wings, what is a good way&lt;br&gt;
&amp;gt; to create an algorithm that takes the picture as input and give the location and/or&lt;br&gt;
&amp;gt; number of spots as output?&lt;br&gt;
&amp;gt; The spots aren't circular.&lt;br&gt;
&lt;br&gt;
I had a look at the image you supplied in a later posting, and it appeared to me that&lt;br&gt;
the number of spots was beyond any easy counting, and it appeared to me that there were&lt;br&gt;
spots that were smaller than the resolution of the image, especially near the body of&lt;br&gt;
the butterfly. This will make the problem quite difficult -- unless, that is, you place&lt;br&gt;
some kind of minimum size as to what is to be considered a &quot;spot&quot;.</description>
    </item>
    <item>
      <pubDate>Fri, 03 Apr 2009 19:44:01 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#640133</link>
      <author>Husam Aldahiyat</author>
      <description>Walter Roberson &amp;lt;roberson@hushmail.com&amp;gt; wrote in message &amp;lt;futBl.41$TD1.22@newsfe18.iad&amp;gt;...&lt;br&gt;
&amp;gt; Husam Aldahiyat wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Say I have a picture of a butterfly with black spots on its wings, what is a good way&lt;br&gt;
&amp;gt; &amp;gt; to create an algorithm that takes the picture as input and give the location and/or&lt;br&gt;
&amp;gt; &amp;gt; number of spots as output?&lt;br&gt;
&amp;gt; &amp;gt; The spots aren't circular.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I had a look at the image you supplied in a later posting, and it appeared to me that&lt;br&gt;
&amp;gt; the number of spots was beyond any easy counting, and it appeared to me that there were&lt;br&gt;
&amp;gt; spots that were smaller than the resolution of the image, especially near the body of&lt;br&gt;
&amp;gt; the butterfly. This will make the problem quite difficult -- unless, that is, you place&lt;br&gt;
&amp;gt; some kind of minimum size as to what is to be considered a &quot;spot&quot;.&lt;br&gt;
&lt;br&gt;
No, no. The spots in interest are the big black thresholdy ones. Each butterfly has either two or four spots only. Some problems occur when I try the dark coloured butterfliies (black spots on grey wings) but things are managable for the most part. &lt;br&gt;
&lt;br&gt;
I have a question: how can I threshold channels? I only know the bw function. Or is it done manually by playing around with the matrix resulting from imread()?</description>
    </item>
    <item>
      <pubDate>Sat, 04 Apr 2009 21:36:01 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#640332</link>
      <author>Image Analyst</author>
      <description>To Husam Aldahiyat, the butterfly scientist:&lt;br&gt;
It looks like the red channel gives the most contrast.  So I thresholded on that.  This code will find the spots for you in the one image that you posted.  It may require some tweaks to make it more robust for lots of other images.  Plus, of course, you may have to fix broken line wraps if you copy and paste this code.&lt;br&gt;
Good luck,&lt;br&gt;
ImageAnalyst&lt;br&gt;
&lt;br&gt;
% Demo macro to find spots on a butterfly wing.&lt;br&gt;
% by ImageAnalyst&lt;br&gt;
clc;&lt;br&gt;
close all;&lt;br&gt;
thresholdValue = 8; % Pick something&lt;br&gt;
% Get a standard MATLAB demo image.&lt;br&gt;
originalImage = imread('C:\Documents and Settings\My Documents\Temporary stuff\200903153435.jpg');&lt;br&gt;
subplot(2, 3, 1);&lt;br&gt;
imshow(originalImage, []);&lt;br&gt;
title('Original image');&lt;br&gt;
&lt;br&gt;
redband = originalImage(:,:,1);&lt;br&gt;
subplot(2, 3, 2);&lt;br&gt;
imshow(redband, []);&lt;br&gt;
title('Red Band');&lt;br&gt;
&lt;br&gt;
thresholdValue = 80;&lt;br&gt;
binaryImage =  redband &amp;lt; thresholdValue;&lt;br&gt;
binaryImage = imfill(binaryImage, 'holes');&lt;br&gt;
subplot(2, 3, 3);&lt;br&gt;
imshow(binaryImage, []);&lt;br&gt;
title('binary image');&lt;br&gt;
labeledImage = bwlabel(binaryImage, 8);     % Label each blob so can do calc on it&lt;br&gt;
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels&lt;br&gt;
&lt;br&gt;
subplot(2,3,4); imagesc(coloredLabels); title('Pseudo colored labels');&lt;br&gt;
&lt;br&gt;
blobMeasurements = regionprops(labeledImage, 'all');   % Get all the blob properties.&lt;br&gt;
% Get a list of the areas.&lt;br&gt;
area_values = [blobMeasurements.Area];&lt;br&gt;
% Filter the blobs by area.  Just keep blobs in a certain area range.&lt;br&gt;
% Find out which blobs have an area between 1000 and 5000 pixels.&lt;br&gt;
% Note: you could also do similar for any of the measurements, such as solidity, etc.&lt;br&gt;
% You can even combine filters over different measurements.&lt;br&gt;
% Use whatever the know valid range for spots area is.&lt;br&gt;
indexes = find((1000 &amp;lt;= area_values) &amp; (area_values &amp;lt;= 5000));&lt;br&gt;
spotsOnlyImage = ismember(labeledImage, indexes);&lt;br&gt;
subplot(2,3,5);&lt;br&gt;
imshow(spotsOnlyImage, []);&lt;br&gt;
title('Spots-only image');&lt;br&gt;
&lt;br&gt;
% Get the subset of blobs that describes only the wing-spot blobs.&lt;br&gt;
blobMeasurements = blobMeasurements(indexes);   % Get the spot properties only.&lt;br&gt;
&lt;br&gt;
% bwboundaries returns a cell array, where each cell&lt;br&gt;
% contains the row/column coordinates for an object in the image.&lt;br&gt;
% Plot the borders of all the coins on the original&lt;br&gt;
% grayscale image using the coordinates returned by bwboundaries.&lt;br&gt;
subplot(2,3,6); imagesc(originalImage); title('Wing spots outlined over original image');&lt;br&gt;
hold on;&lt;br&gt;
boundaries = bwboundaries(spotsOnlyImage);	&lt;br&gt;
numberOfWingSpots = size(blobMeasurements, 1);&lt;br&gt;
for k = 1 : numberOfWingSpots&lt;br&gt;
	thisBoundary = boundaries{k};&lt;br&gt;
	plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);&lt;br&gt;
end&lt;br&gt;
hold off;&lt;br&gt;
&lt;br&gt;
% List the various parameters to the command window.&lt;br&gt;
fprintf(1,'Wing Spot #      Mean Intensity  Area     Perimeter  Centroid\n');&lt;br&gt;
for k = 1 : numberOfWingSpots           % Loop through all blobs.&lt;br&gt;
	% Find the mean of each blob.  (R2008a has a better way where you can pass the original image&lt;br&gt;
	% directly into regionprops.  The way below works for all versions including earlier versions.)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;thisBlobsPixels = blobMeasurements(k).PixelIdxList;  % Get list of pixels in current blob.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;meanGL = mean(originalImage(thisBlobsPixels));             % Find mean intensity (in original image!)&lt;br&gt;
	blobArea = blobMeasurements(k).Area;		% Get area.&lt;br&gt;
	blobPerimeter = blobMeasurements(k).Perimeter;		% Get perimeter.&lt;br&gt;
	blobCentroid = blobMeasurements(k).Centroid;		% Get centroid.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k, meanGL, blobArea, blobPerimeter, blobCentroid);&lt;br&gt;
end&lt;br&gt;
message = sprintf('Done processing this image.\nThere are %d wing spots.\nMaximize and check out the figure window.\nThen check out the command window for the results.', numberOfWingSpots);&lt;br&gt;
msgbox(message);</description>
    </item>
    <item>
      <pubDate>Thu, 09 Apr 2009 16:10:03 -0400</pubDate>
      <title>Re: Detecting spots on a butterfly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/248221#641684</link>
      <author>Husam Aldahiyat</author>
      <description>Wow! That code acted like a full lecture on image processing. I only need to edit it and make it more robust.&lt;br&gt;
&lt;br&gt;
Thanks a lot, you're a lifesaver :)</description>
    </item>
  </channel>
</rss>

