Image matrix cell color

7 ビュー (過去 30 日間)
Wouter Theron
Wouter Theron 2021 年 10 月 10 日
コメント済み: Wouter Theron 2021 年 10 月 10 日
I have imported an image using imread - which creates a matrix of the image. The size of such a matrix is n x m x p. I think p refers to the colour information of each cell. I am using imshow to display these matrices.
Parts of the image, that are white, have the value of 255. How can I change the colour of a specific cell to a colour of my choice? I have tried stuff like X(1,10) = 230, but that doesnt seem to do anything. Could someone please help? Thanks,

採用された回答

DGM
DGM 2021 年 10 月 10 日
編集済み: DGM 2021 年 10 月 10 日
Let's say you just want to change one pixel
A = imread('peppers.png');
newcolor = [230 50 185];
B = A;
B(50,50,:) = newcolor;
imshow(B); hold on
plot(50,50,'wo','markersize',50) % highlight the pixel that changed
Or say you want to change a rectangular block of pixels
B = A;
B(50:100,50:100,:) = repmat(permute(newcolor,[1 3 2]),[51 51]);
clf; % for web view
imshow(B);
Or say you want to change an arbitrary region of the image:
mask = uint8(rgb2gray(A) > 220);
colorpict = uint8(repmat(permute(newcolor,[1 3 2]),size(mask)));
B = A.*(1-mask) + colorpict.*mask;
clf; % for web view
imshow(B);
There are plenty of other ways
  1 件のコメント
Wouter Theron
Wouter Theron 2021 年 10 月 10 日
Exactly what I needed. Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by