Display pixel colors from their known RGB values

3 次查看(过去 30 天)
Hi. I would like to start from the known RGB values (in matrix) to visualize a colored figure.
In detail:
  • I want to create a matrix with "black" pixels (see "matrix_zeros")
  • on this "matrix_zeros" I want to substitute, instead of 0's, the RGB values found in "RGB_matrix" using the coordinates found in "coord_pixel"
  • once the RGB matrix(es) are created, I want to be able to display it as a figure
RGB_matrix = load("RGB_matrix.mat");
RGB_matrix = RGB_matrix.REG_agg;
coord_pixel = load("coord_pixel.mat");
coord_pixel = coord_pixel.coord_pixel_ANA;
matrix_zeros = zeros(520);

采纳的回答

DGM
DGM 2023-2-16
Here's one way.
load coord_pixel.mat
load RGB_matrix.mat
% since no geometry information is known,
% i'm just going to presume that information based on the range of coordinates
sz = [512 512]; % 512? 520?
% convert to linear indices
% i'm going to presume that coordinates are [y x]
idx = sub2ind(sz,coord_pixel_ANA(:,1),coord_pixel_ANA(:,2));
% create output image as a 3-column color table
% REG_agg is improperly-scaled double
% so just create the output in the proper class for the scale (uint8)
outpict = zeros([prod(sz) 3],'uint8');
% insert colors
outpict(idx,:) = REG_agg;
% reshape output
outpict = reshape(outpict,[sz 3]);
imshow(outpict)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by