How to get the binary matrix of an image ?
Mostrar comentarios más antiguos
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
Más respuestas (2)
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
el 21 de Jun. de 2012
Is it possible to use sub2ind in this situation?
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
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
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
el 21 de Jun. de 2012
Makes sense and explains why I couldn't implement my idea!
Image Analyst
el 21 de Jun. de 2012
You could use imline() to "burn" the line into the image, knowing only the endpoints.
Emily
el 22 de Jun. de 2012
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
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
el 24 de Jun. de 2012
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
Image Analyst
el 25 de Mayo de 2013
One way is to threshold a grayscale image
binaryImage = grayImage > thresholdValue;
Categorías
Más información sobre Fractals en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!