How to create binary image file from text file with coordinates of points?

2 次查看(过去 30 天)
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 个评论
Walter Roberson
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
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
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
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')

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by