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.
채택된 답변
추가 답변 (2개)
Walter Roberson
2012년 6월 21일
1 개 추천
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
Ryan
2012년 6월 21일
Is it possible to use sub2ind in this situation?
Walter Roberson
2012년 6월 21일
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
2012년 6월 21일
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
2012년 6월 21일
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
2012년 6월 21일
Makes sense and explains why I couldn't implement my idea!
Image Analyst
2012년 6월 21일
You could use imline() to "burn" the line into the image, knowing only the endpoints.
Emily
2012년 6월 22일
Walter Roberson
2012년 6월 22일
Perhaps if you specify the rectangle to capture when you use getframe() ?
http://www.mathworks.com/help/techdoc/ref/getframe.html
Image Analyst
2012년 6월 22일
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
2012년 6월 24일
faraz.a
2013년 5월 25일
0 개 추천
please tell me how to create a matrix of zeroes and ones for black and white pixels of a binary image.
댓글 수: 1
Image Analyst
2013년 5월 25일
One way is to threshold a grayscale image
binaryImage = grayImage > thresholdValue;
카테고리
도움말 센터 및 File Exchange에서 Fractals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!