Matrix elements to pixel colors

Hello there,
I have a 3000*3000 matrix, elements of which are either 0 or 1. I want to make an image out of it, at which every element matches to a pixel.
The pixels will have black color if the value of the element is 0 and white if the value is 1. Any ideas?
Thank you for your interest!

回答 (2 件)

Voss
Voss 2022 年 2 月 5 日

1 投票

I = randi(2,3000,3000)-1;
my_image = imshow(I);
get(my_image)
AlphaData: 1 AlphaDataMapping: 'none' BeingDeleted: off BusyAction: 'cancel' ButtonDownFcn: '' CData: [3000×3000 double] CDataMapping: 'scaled' Children: [0×0 GraphicsPlaceholder] Clipping: on ContextMenu: [0×0 GraphicsPlaceholder] CreateFcn: '' DeleteFcn: '' HandleVisibility: 'on' HitTest: on Interpolation: 'nearest' Interruptible: off Parent: [1×1 Axes] PickableParts: 'visible' Selected: off SelectionHighlight: on Tag: '' Type: 'image' UserData: [] Visible: on XData: [1 3000] YData: [1 3000]

1 件のコメント

Tasos Kamenides
Tasos Kamenides 2022 年 2 月 6 日
Thank you very much!

サインインしてコメントする。

Image Analyst
Image Analyst 2022 年 2 月 6 日

0 投票

You state "I have a 3000*3000 matrix, elements of which are either 0 or 1. I want to make an image out of it". Well, your matrix already IS an image. There is nothing you have to do. To prove it, you can simply display your matrix:
imshow(yourMatrix, []); % Display yourMatrix as an image.

質問済み:

2022 年 2 月 5 日

回答済み:

2022 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by