Thread Subject: Help with image processing

Subject: Help with image processing

From: M Ladderman

Date: 3 Nov, 2009 10:30:04

Message: 1 of 12

Dear all,

With interest I have read this newsreader and have worked through some demos of matlab. What I want to do is select automatically a fish in my image (because I want to measure its size and color later).

What I get using edge and then filling in the closed spaces. I get pretty good results however not perfect. What I am thinking of now is assining a function that say capture as much (percentage wise) of the picture in a certain shape. What i mean by this because I do not get the fill fish selected that I say that it needs to fit an eggs shape between this and this pixel size to the picture and fit it to the binary mask such that it gets as much of the fish and then fill this. Thereby I select the body of the fish and exclude its caudal fin (the fin at the end of its body). In a similar way I would also like to extract my color reference card (at the left bottom of the pic.)

Is this possible to do and how should I go about it? Or is there a better approach?

I have made a few pictures of my progress.. there are at:
http://picasaweb.google.nl/mirresimons/Matlab#5399822443459403218

Subject: Help with image processing

From: ImageAnalyst

Date: 3 Nov, 2009 13:26:23

Message: 2 of 12

I'm not sure what code you used. Did you try some sort of edge filter
like Sobel, Canny, or Difference of Gaussians? You might have to
combine an edge detected image with other kinds of images, such as the
intensity image or a texture image (such as a variance filter or
something like that). You can use imclose to do a morphological
closing to smooth and connect ragged boundaries.

You can get size if you know your field of view. You will not be able
to get color unless you have a standard in your field of view, such as
the xrite Color Checker Chart.(http://www.xrite.com/
product_overview.aspx?ID=820). This will enable you to compensate for
changes from picture to picture in illumination level and the "color
temperature" of your illumination (hopefully you know what that is).
Otherwise you're just using arbitrary units - you're just using the
"book formulas" which is no better than Photoshop. It's totally
arbitrary and not accurate. That is, if you got an CIE LAB color from
your MATLAB routine, it would not match the values that you would get
if you measured the actual fish via a spectrophotometer or
colorimeter. Your "color reference card" doesn't appear to have any
colors in it so the best you can do is to compensate for overall
intensity level. Even if it were color, there's only 3 patches and
this is not enough to do color correction (picture-to-picture rgb
correction) or color standardization (calibration, or rgb to CIE LAB
conversion).

You might also ask for algorithmic advice in sci.image.processing.
Regards,
ImageAnalyst

Subject: Help with image processing

From: M Ladderman

Date: 3 Nov, 2009 15:56:01

Message: 3 of 12

Hi thanks for your reply ImageAnalyst. Yes I am aware of the problems of measuring colour from photographs. I am intending to calibrate my camera with a colour chart, the reference I have in to correct for small changes in illumination, but I presume there are none (or the effects are negliable) because I use a controlled lighting environment and fixed camera settings.. The colourchart will be used to calibrate my CCD of the camera to be able to be able to compare my study with others.

In reply to your comments on the code (this is just from a demo), but I also tried different edge detections which all 'fail' to detect enough borders to just fill my image. I will try imclose instead of imfill and see what the difference is.. the texture image or intensity image might also be a good idea. I tried applying the edge detection to my blue, red and green channel seperately that improved it a bit but not enough.

However if I use imclose I might still not be able to ignore the tail so using a shape to fit the image is not something that is a good approach??

Thanks!


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <151680ce-a53e-4537-858e-4fd98565d087@s15g2000yqs.googlegroups.com>...
> I'm not sure what code you used. Did you try some sort of edge filter
> like Sobel, Canny, or Difference of Gaussians? You might have to
> combine an edge detected image with other kinds of images, such as the
> intensity image or a texture image (such as a variance filter or
> something like that). You can use imclose to do a morphological
> closing to smooth and connect ragged boundaries.
>
> You can get size if you know your field of view. You will not be able
> to get color unless you have a standard in your field of view, such as
> the xrite Color Checker Chart.(http://www.xrite.com/
> product_overview.aspx?ID=820). This will enable you to compensate for
> changes from picture to picture in illumination level and the "color
> temperature" of your illumination (hopefully you know what that is).
> Otherwise you're just using arbitrary units - you're just using the
> "book formulas" which is no better than Photoshop. It's totally
> arbitrary and not accurate. That is, if you got an CIE LAB color from
> your MATLAB routine, it would not match the values that you would get
> if you measured the actual fish via a spectrophotometer or
> colorimeter. Your "color reference card" doesn't appear to have any
> colors in it so the best you can do is to compensate for overall
> intensity level. Even if it were color, there's only 3 patches and
> this is not enough to do color correction (picture-to-picture rgb
> correction) or color standardization (calibration, or rgb to CIE LAB
> conversion).
>
> You might also ask for algorithmic advice in sci.image.processing.
> Regards,
> ImageAnalyst

Subject: Help with image processing

From: Ashish Uthama

Date: 3 Nov, 2009 16:25:31

Message: 4 of 12

On Tue, 03 Nov 2009 10:56:01 -0500, M Ladderman <mirresimons@gmail.com>
wrote:

> Hi thanks for your reply ImageAnalyst. Yes I am aware of the problems of
> measuring colour from photographs. I am intending to calibrate my camera
> with a colour chart, the reference I have in to correct for small
> changes in illumination, but I presume there are none (or the effects
> are negliable) because I use a controlled lighting environment and fixed
> camera settings.. The colourchart will be used to calibrate my CCD of
> the camera to be able to be able to compare my study with others.
>
> In reply to your comments on the code (this is just from a demo), but I
> also tried different edge detections which all 'fail' to detect enough
> borders to just fill my image. I will try imclose instead of imfill and
> see what the difference is.. the texture image or intensity image might
> also be a good idea. I tried applying the edge detection to my blue, red
> and green channel seperately that improved it a bit but not enough.
>
> However if I use imclose I might still not be able to ignore the tail so
> using a shape to fit the image is not something that is a good approach??
>
> Thanks!

A couple of questions on the setup. Would the fish always be in the same
angle, and always on a background of ice?

"because I use a controlled lighting environment"

Does this mean you can change the camera angle and lighting? If so, then
you could experiment with the best setup which gives you maximum contrast
to segment the fish. If possible a light source shined on to the ice block
 from below/side the surface might work as a backlight and clearly
highlight the fish. You might then even be able to get away with simple
thresholding.
Though, of course, it might not be ideal for color measurements. Maybe you
could take two pictures with the same setup/one with backlight to aid
segmentation and another with controlled light from the top for color
measurements?

I would also imagine the camera has to be exactly overhead to give you
accurate measurements of the size (or at least 'size' in that angle).

Subject: Help with image processing

From: ImageAnalyst

Date: 3 Nov, 2009 16:34:47

Message: 5 of 12

Ashish brings up an excellent point. Why is the fish on ice? That
just makes it more difficult. Why not just use a background that will
enable you to pick out the fish better, such as a black ceramic tile,
or a hot pink powder coated aluminum plate, or some other contrasty
color? There's no need for ice since presumably the fish is only
going to be there for a very short time, just long enough to take the
picture.

Subject: Help with image processing

From: M Ladderman

Date: 3 Nov, 2009 19:42:02

Message: 6 of 12

Hi guys,

The fish is not on ice it is in a small tank with water and what you think is ice is whitish foam.. I could have used black foam but then I think I would have had the same problem with the top of the fish not having a clear 'edge'. I could use different colours however... I do not want reflexion from this. I have now also posted a colour image so that my setup is more clear maybe..

Any more suggestions on coding I could use are very welcome..


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0e74e8f2-0156-4017-9652-c7d9310f174f@d34g2000vbm.googlegroups.com>...
> Ashish brings up an excellent point. Why is the fish on ice? That
> just makes it more difficult. Why not just use a background that will
> enable you to pick out the fish better, such as a black ceramic tile,
> or a hot pink powder coated aluminum plate, or some other contrasty
> color? There's no need for ice since presumably the fish is only
> going to be there for a very short time, just long enough to take the
> picture.

Subject: Help with image processing

From: M Ladderman

Date: 5 Nov, 2009 15:00:04

Message: 7 of 12

Hi after tweaking the settings of my edge detection and using imclose I get pretty close in selecting my fish. However now I have the problem that I do not want to select its tail fin, so the part of the fish on the rightest part of the photograph. So coming back to my point, is there an "easy" way to fit a drop shape (which is pretty much what the fish body looks like) to the binary mask and select only those pixels? I find it hard to think of how to do this. Thanks



"M Ladderman" <mirresimons@gmail.com> wrote in message <hcq12a$cv$1@fred.mathworks.com>...
> Hi guys,
>
> The fish is not on ice it is in a small tank with water and what you think is ice is whitish foam.. I could have used black foam but then I think I would have had the same problem with the top of the fish not having a clear 'edge'. I could use different colours however... I do not want reflexion from this. I have now also posted a colour image so that my setup is more clear maybe..
>
> Any more suggestions on coding I could use are very welcome..
>
>
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0e74e8f2-0156-4017-9652-c7d9310f174f@d34g2000vbm.googlegroups.com>...
> > Ashish brings up an excellent point. Why is the fish on ice? That
> > just makes it more difficult. Why not just use a background that will
> > enable you to pick out the fish better, such as a black ceramic tile,
> > or a hot pink powder coated aluminum plate, or some other contrasty
> > color? There's no need for ice since presumably the fish is only
> > going to be there for a very short time, just long enough to take the
> > picture.

Subject: Help with image processing

From: ImageAnalyst

Date: 5 Nov, 2009 15:04:10

Message: 8 of 12

Can you just find the bounding box and then use imcrop to take, say,
only the left most 80% of the mask?

Subject: Help with image processing

From: M Ladderman

Date: 5 Nov, 2009 15:26:01

Message: 9 of 12

Hi I think this will not yield the results I want because
1. the tail size/body size are variable between fish
2. the edge detection does not always select the whole tailfin becuase it is kinda see through and therefore this will result in cutting of too much

Hope I make sense, thanks for your feedback!

But your suggestion made me think of something else, I could select the fish remove slices starting from the right untill the amount of selected pixels that is removed increase or so (that is when the body thinkens again), does this make sense?


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <998250e5-dd27-4263-81a5-f6d189f72cce@v30g2000yqm.googlegroups.com>...
> Can you just find the bounding box and then use imcrop to take, say,
> only the left most 80% of the mask?

Subject: Help with image processing

From: ImageAnalyst

Date: 5 Nov, 2009 15:34:53

Message: 10 of 12

That might work - just look for the top-most and bottom-most pixel in
each column.
Set some limits to avoid possible noise near the edges (where the tail
thins out), like say you go from the left (nose of the fish) to 97% of
the way to the right, skipping the last 3% or so.
Then scan it from the right and see where the top-to-bottom distance
dips down, which hopefully happens where the tail connects to the
body.
Why don't you post your code?

Subject: Help with image processing

From: Dave Robinson

Date: 5 Nov, 2009 16:27:03

Message: 11 of 12

"M Ladderman" <mirresimons@gmail.com> wrote in message <hcuqq9$psh$1@fred.mathworks.com>...

snip
>" But your suggestion made me think of something else, I could select the fish remove slices starting from the right "

But this technique has the problem that it will almost certainly kill the fish ;-)

I must be in a playful mood - don't know why.

Dave Robinson

Subject: Help with image processing

From: Ashish Uthama

Date: 5 Nov, 2009 19:48:36

Message: 12 of 12

On Thu, 05 Nov 2009 10:00:04 -0500, M Ladderman <mirresimons@gmail.com>
wrote:

> Hi after tweaking the settings of my edge detection and using imclose I
> get pretty close in selecting my fish. However now I have the problem
> that I do not want to select its tail fin, so the part of the fish on
> the rightest part of the photograph. So coming back to my point, is
> there an "easy" way to fit a drop shape (which is pretty much what the
> fish body looks like) to the binary mask and select only those pixels? I
> find it hard to think of how to do this. Thanks
>
>
> "M Ladderman" <mirresimons@gmail.com> wrote in message
> <hcq12a$cv$1@fred.mathworks.com>...
>> Hi guys,
>>
>> The fish is not on ice it is in a small tank with water and what you
>> think is ice is whitish foam.. I could have used black foam but then I
>> think I would have had the same problem with the top of the fish not
>> having a clear 'edge'. I could use different colours however... I do
>> not want reflexion from this. I have now also posted a colour image so
>> that my setup is more clear maybe..
>>
>> Any more suggestions on coding I could use are very welcome..


You might be able to use ideas like active contours (others might
clarify), where you could start out with an average 'drop shape' and then
use gradient maps to fit this shape to the particular fish.

However, doing a better job at the image acquisition stage would be so
much easier :)

For example, with the current image.. simple thresholding would give you a
decent input for your image processing pipeline:

in=imread('in.jpg');
hsv=rgb2hsv(in);
v=hsv(:,:,3);
imtool(v); %use the contrast button to find a good range
%Fish = .24,.5 range
v(v>.24 & v<.5)=0;
imtool(v)

If you can ensure that the fish is placed at the center of a uniformly
white background, you will most likely get much better results. Noting
that the fins are translucent, you might even be able to get rid of them
using the same logic of thresholding.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com