How to get the binary matrix of an image ?
Show older comments
Dear all, I creat a 2-D network by method of fractal interpolation to simulate soil cracks. In my program ,plot(x,y) which plots the network , x,y stand for the points' corrdinate value. I want to compute this network's fractal dimension, but I can't get this image from the figure plotted. My quentions are how to get this image in jpg. or bmp.without white blank like the figure, and how to get the binary matrix of this figure. Thanks in advance.
Accepted Answer
More Answers (2)
Walter Roberson
on 21 Jun 2012
1 vote
getsnap() or getframe(); and then imwrite() or saveas() or print() or use the File Exchange contribution export_fig
You can set the axes background color to something other than white.
10 Comments
Ryan
on 21 Jun 2012
Is it possible to use sub2ind in this situation?
Walter Roberson
on 21 Jun 2012
You can invent a use for sub2ind() in most situations, but there is no obvious reason one would need to convert from multi-dimensional subscripts to linear subscripts for this purpose ?
Were you perhaps thinking of rgb2ind() as part of the process of changing the background color?
Ryan
on 21 Jun 2012
I was thinking of turning the (x,y) vectors into an index which could then be used to turn on the appropriate ones in a zero matrix the size of the image, thus turning the plot into a binary image.
Walter Roberson
on 21 Jun 2012
Unfortunately the endpoints are not enough: you need something like http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
If the endpoints were enough, such as if you were doing a scatter plot, then accumarray() could be useful.
accumarray([X(:), Y(:)], 1, [], @any)
This would require that X and Y both be positive integer and "not too big".
But this isn't going to work for lines, not until you have the coordinate of each pixel in the line.
Ryan
on 21 Jun 2012
Makes sense and explains why I couldn't implement my idea!
Image Analyst
on 21 Jun 2012
You could use imline() to "burn" the line into the image, knowing only the endpoints.
Emily
on 22 Jun 2012
Walter Roberson
on 22 Jun 2012
Perhaps if you specify the rectangle to capture when you use getframe() ?
http://www.mathworks.com/help/techdoc/ref/getframe.html
Image Analyst
on 22 Jun 2012
You're still not as clear as you'd be if you would just upload an image and describe what it is that you want. Mock up some lines on it using Photoshop or whatever to say what part you want to save. Try tinypic.com and pick the last link it give you.
Emily
on 24 Jun 2012
faraz.a
on 25 May 2013
0 votes
please tell me how to create a matrix of zeroes and ones for black and white pixels of a binary image.
1 Comment
Image Analyst
on 25 May 2013
One way is to threshold a grayscale image
binaryImage = grayImage > thresholdValue;
Categories
Find more on Fractals in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!