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

2 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 22 Nov 2012
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 on 22 Nov 2012
And the values, z and z1, never change - they're the same for every row. What are those values and why are they constant?

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 21 Nov 2012
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.
  1 Comment
Jordanka
Jordanka on 21 Nov 2012
Thank you, Image Analyst, for your response. I will try your suggestion. Sorry for not being sufficiently clear.

Sign in to comment.


bym
bym on 21 Nov 2012
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')

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!