Using Image processing toolbox on MATLAB.

In summary: You can use the Property Window to change the Background Image. The background image is stored in the Movie Player's Preference File so you don't have to worry about losing it if you want to change it back.
  • #1
Urmi Roy
753
1
Hi,

I have a movie that contains a particle moving from one end of a channel to another end. The velocity of the particle is super-fast. I need to know how I can estimate the time and pictorially (like using a histogram--similar to plotting the heart pulses of a person) be able to tell when the particle is at each of the ends...I don't care too much about the intermediate path.



I have started using the image processing toolbox on matlab...I'm thinking that my steps will be-
1. to view the movie on movie player (on the image processing toolbox)
2. split the video into individual frames.
3.attach a histogram to each frame, to tell (due to difference in light intensity in the area where the particle is located) in which part of the frame the particle is.
4. now I can tell the time difference between the two frames in which I can see the particle is at each end.

So does anyone have a better idea on how I can achieve my goal?
What functions will I have to use?
 
Physics news on Phys.org
  • #2
Someone told me that for each frame I need to calculate where the spot is,by picking wherever the brightest pixel is or by frame to frame subtracting, calculating means & standard deviations, thresholding, etc...which one would you recommend for me, especially since I'm a beginner in this...I can't code for something too difficult.

After that, I need to calculate the velocity of the particle... by seeing the number of pixels it moves divided by the amount of time between each frame or by using kalman filters.

I've heard about kalman filters...but how do I employ this? I need an easy code...nothing too complex..

please suggest...I'm in soup!
 
  • #3
Is the background of your movie constant (sounds like it would be). If so, the first thing you want to do is average all of the frames and subtract that average from each frame. This will leave you with just the particle in each frame.

From there it should be pretty easy to figure out which ones are blank and remove them. The first frame you are left with is when the particle entered the video and the last frame you are left with is when the particle left the video.


If you background isn't constant then identifying the particle from things moving in the background becomes much more difficult...
 
  • #4
I've tried different videos, and all of my avi videos are working on movieplayer (MATLAB), except one...which is the one that I need.
Before I proceed to follow Floid's instructions and analyse the images, it is important that I be able to split this video into its frames...

I can't bring the video on the workspace, and aviread cannot read it...

I can, however play it using
implay('cell.avi')

But now, I need to separate out its frames (maybe using image function?)...please suggest a code for this..

Apparently, my video 'cell.avi' is a 8 character long string..
 
  • #5
Hey, I managed to convert the file atlast!

Floid, here's the frame...if u see carefully, you will be able to locate a time cell at the bottom left hand corner of the frame...

Please tell me what u would suggest for me to do..as u can see, the cell isn't easy to make out from its background..

How would I write the code to subtract the background from the image?
 

Attachments

  • untitled.jpg
    untitled.jpg
    6.8 KB · Views: 564
  • #6
Take a frame that you know does not have a cell in it as your "background" image. Now subtract the background image from every frame of the video. This will in effect remove the background from the video and all will you be left with is a video of the cell.

Actual implementation you will have to figure out as I have never tried it, but I know that is how you separate foreground objects from background objects (as long as the background is fairly constant). You can do it pixel by pixel but if you have Matlab Image Processing Toolbox there probably is a built in function to do it.
 
  • #7
But I just realized that I also need some way to measure the displacement of the cell...is it possible to select a point and measure the pixel displacement or something?...How about using control points?

I'm completely new to this...please help.
 
  • #8
I managed to subtract the frames and I'm getting my desired result...now can you suggest how I can-
1. measure how much the cell has moved from one point of time to another.
(it doesn't even show coordinate axes)

2. how can I make the image of the moving cell more clear...its a faint white blob moving from frame to frame...
 
Last edited:
  • #9
To answer 2.) first:

Are you worried about clarity/accuracy of what you are looking at?

If all you want to do is make the cell location more visible but don't care about what the cell itself actually looks like the easiest way will be to change the image to black/white. The basic idea is that all colors below some level will be converted to white (your background) and all colors above some level (your cell) will be converted to black. What you will end up with is a white background with a black blob that is your cell. This will make step 1 easier if it is acceptable.

Look into the MATLAB image processing function dither. http://www.mathworks.com/help/techdoc/ref/dither.html

It didn't look like it had a threshold level you could set for white and black, so you may have to write a loop that goes through every pixel of the image and makes a decision to change it to black or white.


To question 1.)

You need to know a few things to measure distance travelled. The first is the frame rate of the video (needed to get time). This should be easy to determine.

The next part is an idea of distance and can be a little harder. One way is to have a scale, which may be what that rectangular thing in the back of your image is... even if it isn't you can use it as one. Ideally you can establish the size of one pixel. One way to do this is that if you know the actual size of that rectangular thing is to count the pixels between those 45 degreeish slanted boxes and then measure how far it is actually between them. You can use this to establish the size of a pixel.

Now, all you have to do is take two images that both feature the cell and measure the distance between them in pixels which will give you distance and take the difference in frame numbers divided by the frame rate (in Hz) to give you time.

How to find the cell itself? If you convert to black and white like in 2.) then search through all the pixels of the image and find the left most or right most black pixel and this should give you an edge of the cell and then do the same search and find the top most or bottom most black pixel and this will give you the top or bottom of the cell.

Do the same measurements between different frames and you can get the displacement in pixels of the cell.
 
  • #10
Hi Floid, thanks for your help!

I subtracted the first frame as u said, and it left me with only the cell moving...but it was very faint against the background..

Then I tried dither as u said...but unfortunately, there must be other point with the same intensity as the cell, since I get multiple indistinguishable white spots...

I also tried imclear, but again, due to the fact that there must be other spots indistinguishable from the cell, the result was never satisfactory..

Also, the frame, after subtraction of the first frame, consists of a black background with a faint white blob, which is the cell...and even after converting it to grayscale (using rgbgray), doesn't make any difference in the output..

So I'm still stuck with the first part of your answer...
 
  • #11
I just did it using imcontrast function...it worked!...now I'll try working with the second part of your answer.
 
  • #12
I've done a large part of Floid said in the second part of his answer...I'm calculating the displacement of the cell by putting all the frames into a matrix...the cell is the brightest pixel on each frame...I'm therefore calculating the difference of the x,y coordinates of the brightest spot on each frame...any idea what's wrong with my for loop?

It says ERROR IN USING - (MINUS SIGN)...MATRIX DIMENSIONS MUST MATCH.

This is the for loop:

Bii=B1{ii};
for ii= 1:N
Bii=B1{ii};
[x,y]=find(B1{ii}==max(max(B1{ii})));
[x,y]=find(B1{ii}==max(max(B1{ii})))
end
 
  • #13
Note that this is supposed to be a modification of the following code that does work...

Bii=B1{ii};
for ii= 1:N
Bii=B1{ii};
[x,y]=find(B1{ii}==max(max(B1{ii})));
[x,y]=find(B1{ii}==max(max(B1{ii})))
end
 
  • #14
I discovered that its because there are multiple points with the same (maximum) intensity...so I guess I can't track the cell on the basis of brightness... any idea how else/what other basis I could identify the cell's position?
 
  • #15
All the preliminary points having been solved, I have a new problem!

I have some new videos in which again, a cell moves along a channel...however, the background i.e. the channel is near the brightness of that of my cell, so when I convert the video into images of its frames, and turn them into grayscale images, I cannot isolate the cell from its background very clearly, though I can faintly see it move against the background.

I tried frame subtraction..after subtracting the first frame that does not contain the cell from the remaining, I still get a lot of background noise. *

Thus, when I try locating the cell by trying to identify the maximum brightness spot, *I get the locations of different other points with the greater brightness than the cell.

Can you suggest what I can do?
 

1. What is the Image Processing Toolbox in MATLAB?

The Image Processing Toolbox is a collection of functions and algorithms specifically designed for processing and analyzing digital images. It provides a wide range of tools for image enhancement, segmentation, feature extraction, and other image processing tasks.

2. How do I access the Image Processing Toolbox in MATLAB?

The Image Processing Toolbox is a built-in feature of MATLAB, so there is no need to install or download it separately. It can be accessed by typing "ipt" in the MATLAB command window, or by clicking on the "Image Processing Toolbox" option in the "Apps" tab of the MATLAB toolbar.

3. What types of image files can be processed using the Image Processing Toolbox?

The Image Processing Toolbox is compatible with a variety of image formats, including JPEG, PNG, TIFF, BMP, and GIF. It can also handle multidimensional and grayscale images.

4. Can I perform basic image editing tasks using the Image Processing Toolbox?

Yes, the Image Processing Toolbox includes a set of basic image editing functions such as cropping, resizing, and rotating images. These functions can be applied to both individual images and batches of images.

5. Are there any tutorials or resources available for learning how to use the Image Processing Toolbox in MATLAB?

Yes, there are many online tutorials, videos, and documentation provided by MathWorks, the company behind MATLAB. You can also find helpful resources on online communities and forums, as well as in the official MATLAB documentation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
15
Views
2K
Back
Top