Transforming a matrix in an image

1 回表示 (過去 30 日間)
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 10 日
コメント済み: Oliver Lestrange 2020 年 8 月 10 日
Hi community,
I am transforming a matrix in an image, but when I try to see the green and blue components of the image a get the error Index exceeds matrix dimensions.
dmin1=2;
n=15;
A=ones(n);
A(2:dmin1:end,2:dmin1:end)=0;
im = imshow(A,[])
%im = image(im,'CDataMapping','scaled')
...
... % code that add some colors to im
R=im(:,:,1)
G=im(:,:,2)
B=im(:,:,3)
What I'm doing wrong?
  4 件のコメント
VBBV
VBBV 2020 年 8 月 10 日
編集済み: VBBV 2020 年 8 月 10 日
Try using dmin1 = 1; as the increment step.
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 10 日
I can't do that Vasishta Bhargava, that will change the appearance of the matrix.

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

採用された回答

Image Analyst
Image Analyst 2020 年 8 月 10 日
First of all, your image is A, not im. im is what imshow returns and it is the handle to an image object, not an actual image itself. Secondly, you declared A as a 2-D gray scale image, not a 3-D color image. You'd need to make A like this:
A=ones(n, n, 3);
A(2:dmin1:end, 2:dmin1:end, :) = 0;
R = A(:,:,1)
G = A(:,:,2)
B = A(:,:,3)
or
[R, G, B] = imsplit(A);
  1 件のコメント
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 10 日
Thanks a lot!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by