MATLAB CODE

408 views
Skip to first unread message

Sterling

unread,
Mar 6, 2012, 5:58:28 PM3/6/12
to bmed...@googlegroups.com
You may try this code I wrote. It uses normxcorr2, a correlation will return numbers from 0-1 with one being a perfect correlation between the template and the whole image. The program then searches for the highest value and prints a grid tracking the movement of all the pieces. Adjust variable 'ps' to change the number of patches it breaks the image up too. Fewer patches will run faster. Try to modify the code and make it better.
Sterling
twoD_strain_map3.m

Sarah Mailhiot

unread,
Mar 8, 2012, 1:06:25 PM3/8/12
to BMED2540
Hey!! I tried this code but I got these errors...

??? Error using ==> normxcorr2>checkIfFlat at 281
The values of TEMPLATE cannot all be the same.

Error in ==> normxcorr2>ParseInputs at 242
checkIfFlat(T)

Error in ==> normxcorr2 at 55
[T, A] = ParseInputs(varargin{:});

Error in ==> twoD_strain_map3 at 24
pos = normxcorr2(temp, dim);

Does this code run? Or am I doing something wrong? Does it need any
other editing?
>  twoD_strain_map3.m
> 2KViewDownload

Sterling

unread,
Mar 8, 2012, 1:30:00 PM3/8/12
to bmed...@googlegroups.com
This code will run with no modification. You only need to change the file path for 'im' and 'dim' to the file paths for your images. As for your errors, its hard without seeing your images or code, but I am guessing that some part of your image is saturated, hence the values will be all the same for one of the patches/templates.
 
Sterling

Sarah Mailhiot

unread,
Mar 8, 2012, 1:34:50 PM3/8/12
to bmed...@googlegroups.com
How do I know if an image is saturated and what do I do about it?
--
Sarah Mailhiot
Rensselaer Polytechnic Institute
Biomedical Engineering
Class of 2013

Sterling

unread,
Mar 8, 2012, 2:26:45 PM3/8/12
to bmed...@googlegroups.com
You can display the image (ie imshow(x)) where x is the name of your image loaded in matlab. There you can place the cursor and look at the intensity for each pixel. Also, this code is set up for RGB images, and it only calls the red part of the image. If you do not have RGB images then remove the line of code just after loading the images (ie im = im(:,:,1); and dim = dim(:,:,1);) or you can write better code that will combine the three parts of RGB images into one grayscale image.

stephanie krom

unread,
Mar 8, 2012, 10:20:35 PM3/8/12
to BMED2540
What do these errors mean? or where do get the file it is referring
to??


??? Error using ==> imread at 372
File
"C:\Users\sterling\Documents\classes\TA\imagingcorrelationmatlabcode
\ogl.jpg"
does not exist.




Error in ==> Untitled at 1
im =
imread('C:\Users\sterling\Documents\classes\TA
\imagingcorrelationmatlabcode\ogl.jpg');
>>

On Mar 8, 2:26 pm, Sterling <sterling.nesb...@gmail.com> wrote:
> You can display the image (ie imshow(x)) where x is the name of your image
> loaded in matlab. There you can place the cursor and look at the intensity
> for each pixel. Also, this code is set up for RGB images, and it only calls
> the red part of the image. If you do not have RGB images then remove the
> line of code just after loading the images (ie im = im(:,:,1); and dim =
> dim(:,:,1);) or you can write better code that will combine the three parts
> of RGB images into one grayscale image.
>
>
>
>
>
>
>
> On Thursday, March 8, 2012 1:34:50 PM UTC-5, Sarah Mailhiot wrote:
> > How do I know if an image is saturated and what do I do about it?
>

Eric Sellke

unread,
Mar 9, 2012, 11:42:32 AM3/9/12
to bmed...@googlegroups.com
Can we please get an extension for the Monday back from spring break? 

Sterling

unread,
Mar 9, 2012, 11:56:53 AM3/9/12
to bmed...@googlegroups.com
You have to change the file path to images that are on your computer's hard drive. If you are running it without making any changes it will try to read an image from my hard drive, which it can't do.

On Thursday, March 8, 2012 10:20:35 PM UTC-5, stephanie krom wrote:

Sterling

unread,
Mar 9, 2012, 11:57:53 AM3/9/12
to bmed...@googlegroups.com
Sounds reasonable. I don't decide the due dates. You will have to ask Dr. Kotha or Dr. Wan.

Sterling

unread,
Mar 9, 2012, 4:18:44 PM3/9/12
to bmed...@googlegroups.com
Here is an example of what the results with this code should look like.


For this code to work you need to have a high amount of contrast, with random patterns. Use a black marker and draw lots of random dots and lines on the elastic part of the bandage, the more random the better the correlation.

Sterling

Sterling

unread,
Mar 9, 2012, 4:20:19 PM3/9/12
to bmed...@googlegroups.com
This code will not work well with the example images given in class. There are not enough dots. Plus the dots look alike and the code will confuse them.

Sterling

unread,
Mar 9, 2012, 6:55:45 PM3/9/12
to bmed...@googlegroups.com
I saw some other people that were having a similar problem. What happens is if you use the example images from class there are large grey areas that are all the same color (ie grey) when the program breaks the image up into patches/templates and tries to correlate them, it gets an error because the template can not have the same value for all the indecies.
 

Katelyn Rimkunas

unread,
Mar 9, 2012, 10:35:11 PM3/9/12
to BMED2540
Hi, I came to your office hours today so I know what I'm supposed to
do and what's supposed to happen but when I run the program nothing at
all happens. I don't get any errors but matlab seems to be stuck
running it. It says "Busy" in the corner and that's all that happens.
Matlab already froze my computer because of this. I've tried to run it
with my images, with one of my images that I then stretched in paint,
with the sample images and with a smaller contrast-y picture from the
internet that I stretched in paint also. Nothing works and I don't
know what to do. I also tried changing "ps" to various numbers ranging
from 1 to 50 several times and matlab continues to do nothing. What
should I do?

On Mar 6, 5:58 pm, Sterling <sterling.nesb...@gmail.com> wrote:
>  twoD_strain_map3.m
> 2KViewDownload

Rebecca P.

unread,
Mar 10, 2012, 7:23:48 AM3/10/12
to BMED2540
Hi Katelynn,
This code takes a long time to run; it goes through a lot of loops. I
set ps to 300, and it still took about 5 minutes. Also, it will take
longer if your image is really big, so I cropped mine down to about
1500x1500 pixels. I know Sterling said it should take less time for
smaller ps, but it seemed to take more time for smaller ps for me, Try
running it with ps at 300 and wait to see what you get.

Also, to Sterling:
I've run mine, and posted my image on the doc, but mine looks nothing
like yours. I used an original image of dots on a stretched latex
glove, and the resulting strain grid is all over the place. I'm
assuming it's because the program confused the dots (I was not aware
that could happen, so I did not make the dots different). I just want
to make sure that will be okay anyway. I'm out of town now and cannot
take another image before Monday.

On Mar 9, 10:35 pm, Katelyn Rimkunas <katelyn.rimku...@gmail.com>
wrote:

stephanie krom

unread,
Mar 10, 2012, 11:50:27 AM3/10/12
to BMED2540
Sterrling,

Ive been using your code with other images that I have been getting
off the internet and the grid on the unstreched comes up fine but the
grid on the stretched always comes up very disorganized. Ive tried the
program using dots, no dots, different colored dots, different shaped
dots, and the same thing happens over and over again...Ive been
changing the "ps" value also and I cant get the grid on the stretched
to be more organized. Is there anything else in the code that can fix
this?

Sterling

unread,
Mar 10, 2012, 12:08:11 PM3/10/12
to bmed...@googlegroups.com
try with these images. set 'ps' to 100.
abraham-lincoln-picture.jpg
abraham-lincoln-picture2.jpg

stephanie krom

unread,
Mar 10, 2012, 12:13:16 PM3/10/12
to BMED2540
the grids are still very disorganized
>  abraham-lincoln-picture.jpg
> 42KViewDownload
>
>  abraham-lincoln-picture2.jpg
> 48KViewDownload

Kevan Chao

unread,
Mar 10, 2012, 6:35:33 PM3/10/12
to bmed...@googlegroups.com
That would really help. I'm getting all sorts of installation errors from the SolidWorks lisencing. If we push it to the monday after that'd be a great. Eric, if you get any response from the professor please do tell. If not I may just need to purchase a copy of solidworks =/

Lydia Dumont

unread,
Mar 10, 2012, 7:54:31 PM3/10/12
to BMED2540
Sterling,
My grids are also very unorganized using the latex bandage. I've tried
a lot of different random lines and dots on the latex, and matlab
cannot seem to organize them. Changing the ps value does not help to
organize it. I am having more success in getting a grid pattern with
another image. Should we just use a picture from the internet?

stephanie krom

unread,
Mar 11, 2012, 11:29:31 AM3/11/12
to BMED2540
the code was working yesterday but now i am getting this error


??? Error using ==> sym.subsasgn at 57
Error using ==> maplemex
Error, (in MTM:-subsasgn) invalid left hand side in assignment

Error in ==> work at 37
x(nn) = current_row;


what does this mean??

Sterling Nesbitt

unread,
Mar 29, 2012, 4:35:14 PM3/29/12
to bmed...@googlegroups.com
I am not sure what that error means.
--
Robert Sterling Nesbitt
PhD Candidate
Rensselaer Polytechnic Institute
Department of Biomedical Engineering

Reply all
Reply to author
Forward
0 new messages