Graph the randomization of a binary image

1 view (last 30 days)
I have zero MATLAB experience, but have been asked to work in it to do some image analysis. I'll try and ask my question as specifically and concisely as possible.
Imagine the following binary image exemplified by the matrix below. This is a simplified version of the images I'll be working with:
0 1 0 1
0 1 1 1
0 0 0 1
0 1 1 1
I want to construct a graph that will represent the randomness of each column. My thought is to develop a random index = the total transitions between each value in the column / by the total possible transitions. In the matrix above, each column could have a total possible of 3 transitions.
For the example above: column 1 would have a random index of 0 (0/3)
Column 2 would have a random index of 66.7 (2/3)
Column 3 = 100% (3/3)
Column 4 = 0 (0/3) even though they are 1's and not 0's. Doesn't matter, I just want the transitions.
Can I draw a boundary around all the 1 values and then have MATLAB sum all of the boundaries(only idea I have)?
Again, I have zero experience in MATLAB, but have been asked to do this (for me) impossible task. Any help would be greatly appreciated!

Accepted Answer

Image Analyst
Image Analyst on 24 Jun 2014
Take a look at the diff() function.
m=[...
0 1 0 1
0 1 1 1
0 0 0 1
0 1 1 1]
dm = diff(m)
randomnessIndex = sum(abs(dm))/(size(m, 1)-1)
m =
0 1 0 1
0 1 1 1
0 0 0 1
0 1 1 1
dm =
0 0 1 0
0 -1 -1 0
0 1 1 0
randomnessIndex =
0 0.66667 1 0
  3 Comments
Joshua Mangler
Joshua Mangler on 24 Jun 2014
Excellent! Thank you very much. Works exactly how I want it to.
Image Analyst
Image Analyst on 24 Jun 2014
Can you go ahead and officially mark the answer as "Accepted" and vote for it. Thanks in advance.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!