How can I change the color of a grid?

32 views (last 30 days)
leonardo araujo
leonardo araujo on 23 Apr 2016
Answered: Lori Lewis on 9 Dec 2018
Dear users,
I'm intending to draw a grid on a image for point count using the command:
Ig2(50:50:end,:,:) = 0;
Ig2(:,50:50:end,:) = 0;
imshow(Ig2);
Over the image a black grid is draw. How do I change the color of the grid to yellow or red?
BR,

Answers (2)

Daniel
Daniel on 6 May 2016
If I were to check the size of your image matrix Ig2 I would see that
size(Ig2)
returns
x y c
Where x is the number of row in your matrix.
Where y is the number of columns in your matrix
Where c is of value 3 because you need to specify the intensity of Red, Green, Blue for each pixel.
So for any pixel that is at row 'i' and column 'j' I can choose the colour by changing the intensity of Red, Green and Blue in the following way:
Ig2(i,j,1) = 1; %Set red to full intensity
Ig2(i,j,2) = 0; %Set green to zero intensity
Ig2(i,j,3) = 0; %Set blue to zero intensity
Now the pixel at location i,j will be red.
Back to your problem. To get a red grid all you need to do is the following:
Ig2(50:50:end,:,1) = 1;
Ig2(50:50:end,:,2) = 0;
Ig2(50:50:end,:,3) = 0;
Ig2(:,50:50:end,1) = 1;
Ig2(:,50:50:end,2) = 0;
Ig2(:,50:50:end,3) = 0;
imshow(Ig2);
Play with the values on the right hand side to get different colours. Hint: to get yellow you have to mix red and green.

Lori Lewis
Lori Lewis on 9 Dec 2018
set(gca, 'Color', 'r')

Categories

Find more on 3-D Scene Control in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!