0
votes

Hi I am trying to draw an image.

I have three matrices:

Matrix A: X coordinates

Matrix B: Y coordinates

Matrix C: Image gray scale

For example:

A = [1, 1;     B = [1, 2;       C = [1, 2;
     2, 2]          1, 2]            3, 4]

I will plot a point with value of C(1) at X(1), Y(1). Value 1 is drawn at (1,1) Value 2 is drawn at (1,2) Value 3 is drawn at (2,1) Value 4 is drawn at (2,2)

Is there a function that I can use to plot this, or do I have to implement this? Any suggestion how to implement this would be appreciated it. Thank you.

1
Now is this a one to one mapping, i.e, is there only one C value per (x,y) pair? More, specifically, what do X and Y matrices look like?voxeloctree
They are all 2D matrices with the exact same size. I am not sure what you mean by one to one maping. So C(1) value is used at X(1), Y(1). C(2) value is used at X(2), Y(2), and so on.J L
You can read more about them online, look up injective functions. Sorry to confuse you, I was confused. But you made it more understandable with your sample A,B,C matrices.voxeloctree

1 Answers

0
votes

Is it a full image? And A, B, and C are 1D, right? If so you could make a 2D array with the values of Matrix C at the corresponding indices, convert it to an image and display the images.

img = zeros(max(max(B)),max(max(A)));   %initialize the new matrix
for i = 1:numel(C)                      %for each element in C
        img(B(i),A(i)) = C(i);          %fill the matrix one element at a time
end
img = mat2gray(img);                    %optional. More information in edit
imshow(img);                            %display the image

This assumes that the minimum index value is 1. If it is 0 instead, you'll have to add 1 to all of the indices.

My matlab is a little rusty but that should work.

edit: Is there any reason why they are two dimensional arrays to start? Regardless, I've updated my answer to work in either case.

edit2: mat2gray will scale your values between 0 and 1. If your values are already grayscale this is unnecessary. If your values range another scale but do not necessarily contain the min and max values, you can specify the min and max. For example if your range is 0 to 255, use mat2gray(img,[0,255]);