How to get the binary matrix of an image ?
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (2)
Walter Roberson
il 21 Giu 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 Commenti
Ryan
il 21 Giu 2012
Is it possible to use sub2ind in this situation?
Walter Roberson
il 21 Giu 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
il 21 Giu 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
il 21 Giu 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
il 21 Giu 2012
Makes sense and explains why I couldn't implement my idea!
Image Analyst
il 21 Giu 2012
You could use imline() to "burn" the line into the image, knowing only the endpoints.
Emily
il 22 Giu 2012
Walter Roberson
il 22 Giu 2012
Perhaps if you specify the rectangle to capture when you use getframe() ?
http://www.mathworks.com/help/techdoc/ref/getframe.html
Image Analyst
il 22 Giu 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
il 24 Giu 2012
faraz.a
il 25 Mag 2013
0 voti
please tell me how to create a matrix of zeroes and ones for black and white pixels of a binary image.
1 Commento
Image Analyst
il 25 Mag 2013
One way is to threshold a grayscale image
binaryImage = grayImage > thresholdValue;
Categorie
Scopri di più su Fractals in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!