change color of output graph

조회 수: 4 (최근 30일)
Anvinder  Singh
Anvinder Singh 2016년 3월 2일
댓글: Anvinder Singh 2016년 3월 2일
I have a matlab plot (draw rectangle using matrix) but it shows the output in blue color whereas i want it in black color. How can i change it to black color ?
a = ones(256, 256, 3);
a(10:110,40:140)=0;
a(120:200,120:200)=0;
image(a)
I want the intensity of each square to be different actually. One should have intensity 100 and the other to be 300.
  댓글 수: 1
Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 3월 2일
please format your question.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2016년 3월 2일
Anvinder - the problem is with the following two lines
a(10:110,40:140)=0;
a(120:200,120:200)=0;
Remember, a is a 256x256x3 matrix. In the above, you are only setting the Red component to zero. These two lines would be equivalent to
a(10:110,40:140,1)=0;
a(120:200,120:200,1)=0;
If you want the squares to be black, then you need to set all three components (red, green, and blue) to zero using
a(10:110,40:140,:)=0;
a(120:200,120:200,:)=0;
When I try the above, the pale blue squares are replaced with black ones.
  댓글 수: 2
Anvinder  Singh
Anvinder Singh 2016년 3월 2일
Thanks Geoff, This is awesome. I didnt think about the third component at all. One more query, If i need to vary the intensity of the squares to some other grayscale value then should i do it by replacing '0' in the equation above or do something else ?
Geoff Hayes
Geoff Hayes 2016년 3월 2일
Yes, Anvinder. Just use any value between 0 and 255.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2016년 3월 2일
You can use an indexed image if you don't want an RGB image and want values of 0, 100, and 300, and want the 100 and 300 both to show up as black. Just set up a colormap and apply it.
a = zeros(256, 256);
a(10:110,40:140) = 100;
a(120:200,120:200) = 300;
imshow(a, []);
cMap = [1,1,1;0,0,0]
colormap(cMap);
colorbar
caxis([0, 100]);
  댓글 수: 1
Anvinder  Singh
Anvinder Singh 2016년 3월 2일
Thank you Image analyst ! That looks good to implement!

댓글을 달려면 로그인하십시오.


Muhammad Usman Saleem
Muhammad Usman Saleem 2016년 3월 2일
편집: Muhammad Usman Saleem 2016년 3월 2일
  댓글 수: 1
Anvinder  Singh
Anvinder Singh 2016년 3월 2일
plot(array1,array2,'k')%k stand for black color doesnt work for this plot. Why will i get blue plot in the first place when i give the value of the two rectangular matrices =0 ? Shouldnt it give a black rectangle ?
Is there a way to change the color of the rectangles i plot using matrix such that each rectangle can have different intensity..

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by