How to create binary image file from text file with coordinates of points?
이전 댓글 표시
Hello, I wrote a script creating number of files, each one containing x,y,z coordinates of four different points (practically a 3x4 matrix ). How can I now transform these files in binary image files? I would like then to stack each set of 24 binary images into single 24bit image in a way such that instead of being identified with one digit (0 or 1) each pixel should be identified with 24 (101111....), each digit corresponding to the value of the relevant pixel of every single binary image. Thank you!
댓글 수: 5
Lalit Patil
2012년 11월 21일
I have the same problem.. I want to create binary image from 2D data.. I have x and y..
What have you tried so far? Is there any code to find the files, to read them one by one, to convert them into an array? Please post the existing code even if it does not work already, and explain the occurring problems.
While the forum is very active for solving problems, when they are described explicitly, it is very lazy, when there is the impression, that we should solve the work others. The usually the "doit4me" and "no_attempt" tags are added and most users do not care anymore.
Jordanka
2012년 11월 21일
Walter Roberson
2012년 11월 22일
Are z and z1 constant?
You write two values for each (x,y) pair. What value should appear in the binary image at that (x,y) location?
Image Analyst
2012년 11월 22일
And the values, z and z1, never change - they're the same for every row. What are those values and why are they constant?
답변 (2개)
Image Analyst
2012년 11월 21일
I didn't quite follow what you're generating and don't know the range of your numbers or which one is supposed to be the red, green, and blue, or if your 24 bit image is an RGB image or a 24 bit grayscale image, or how you're defining "binary". In image processing, binary means a 0 or 1 logical/boolean image. If so, then that's not a 24 bit RGB image with 8 bits (0-255) for the red value, 8 bits for the green value, and 8 bits for the blue value. Maybe you mean binary, like all computer variables are binary, of course. I have no idea. So overall, it's not clear what you want. But in general you can instantiate a color image like this:
rgbImage = zeros(300, 400, 3, 'uint8');
and then assign values like this:
rgbImage(row, column, 1) = redValue;
rgbImage(row, column, 2) = greenValue;
rgbImage(row, column, 3) = blueValue;
Make sure the values are in the range 0-255 if you want to display the image with imshow() or image(). Scale them and cast to uint8 if you have to.
bym
2012년 11월 21일
I don't know if this will help, but I thought I would try it. Basically it takes a 3 dimensional logical matrix (n x 24) and converts it to a n x 3 RGB matrix. I'm sure there are better implementations; just can't think of them now.
clc;clear
a = rand(20,20,24);
b = a < .15; %create logical matrix
cb = char(b+48);
rgb = zeros(20,20,3);
for m = 1:3
for c = 1:20
for r = 1:20
t = squeeze(cb(r,c,m*(1:8)))';
rgb(r,c,m) = bin2dec(t);
end
end
end
imshow (rgb,'InitialMagnification','Fit')
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!