How to get the binary matrix of an image ?

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.

 Respuesta aceptada

Image Analyst
Image Analyst el 21 de Jun. de 2012

0 votos

Emily, If you want an image of your cracks, first I'd create a blank image with zeros(). Then I'd go down through every x,y pair that you have using imline() to draw the line (crack) from one point to the next. Now you have your image with all your cracks on it, and you can use export_fig() to write it out to a standard format image file. This will give you just the image alone - no tick marks and titles etc.
However if you want a plot, rather than an image, I'd continue doing it the way you are and then use export_fig() to get the whole plot - including the title, x and y axis labels, tick marks, outer plot area bounding box, etc.
I don't really see how the image of the cracks is going to help you calculate the fractal dimension of the crack network though. I don't use fractals but I though the fractal dimension of a 2D image would look at all the pixel values of all the pixels to give a metric that is kind of related to the "roughness" of the image, but that wouldn't be appropriate to get the fractal dimension of a binary image of a crack network.

3 comentarios

Emily
Emily el 22 de Jun. de 2012
Hi, thanks for your answer.
i'm sorry i should have been clearer in my quenstion. Base on statistics of actual cracks, the stages i get the crack network are listed as follws: first, generating random dots according to the actual node density of cracks per m2; second, creating random network based on a relationship of nodes' connection; third, generating inflections between two nodes connected, calculate the corrdinate of the infections; last, according to the nodes and inflections in order, using the fractal interpolation to interpolate, then these dots formede the network. I'm stucked in the last stage, in this stage, the interpolated iterations are decided by fractal dimension of the image i get compared with the actual networks, when the the fractal dimension reaches to the actual, the iteration end, otherwise, continue. Now i don't know how to get the iterations.
Please forgive my poor English, thanks again.
Image Analyst
Image Analyst el 22 de Jun. de 2012
It doesn't really seem like an imaging problem, other than you could generate an image or a plot of the crack network, and I'm not a fractal expert so I'm going to bow out. I'm just going to suggest that you edit your post from "How to get the binary matrix of an image ?" to "Determine fractal dimension of network of cracks" so that some fractal experts might find it and help you. Of course they'll also want to see some kind of plot or image like I asked you for earlier so do that now.
Emily
Emily el 24 de Jun. de 2012
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 21 de Jun. de 2012

1 voto

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 comentarios

Ryan
Ryan el 21 de Jun. de 2012
Is it possible to use sub2ind in this situation?
Walter Roberson
Walter Roberson el 21 de Jun. de 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
Ryan el 21 de Jun. de 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
Walter Roberson el 21 de Jun. de 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
Ryan el 21 de Jun. de 2012
Makes sense and explains why I couldn't implement my idea!
Image Analyst
Image Analyst el 21 de Jun. de 2012
You could use imline() to "burn" the line into the image, knowing only the endpoints.
Emily
Emily el 22 de Jun. de 2012
Hi, Walter Roberson
Thanks for your quick answer. I'm sorry, I should have been clearer in my question. I tried the getframe() and imwrite() to get the image, it seems to work. While the image i get is still not satisfactory, the quenstion is not the background, but there is blank area around the image, i want to remove the blank area.
Please forgive my poor English. Thanks again.
Walter Roberson
Walter Roberson el 22 de Jun. de 2012
Perhaps if you specify the rectangle to capture when you use getframe() ?
http://www.mathworks.com/help/techdoc/ref/getframe.html
Image Analyst
Image Analyst el 22 de Jun. de 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
Emily el 24 de Jun. de 2012
Thanks again!

Iniciar sesión para comentar.

faraz.a
faraz.a el 25 de Mayo de 2013

0 votos

please tell me how to create a matrix of zeroes and ones for black and white pixels of a binary image.

1 comentario

One way is to threshold a grayscale image
binaryImage = grayImage > thresholdValue;

Iniciar sesión para comentar.

Categorías

Más información sobre Fractals en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Jun. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by