How to convrt parts of grayscale to RGB

1 view (last 30 days)
Yubin ZHONG
Yubin ZHONG on 6 Nov 2019
Commented: ME on 7 Nov 2019
It's not simply convert a whole figure.
I just want to use a simple methods to finish a line trace. Like mark the air flow on a photo of wind tunnel experiment
The idea is convert the photo to grayscale first
Then check the grayscale of each pixel in a specific area
If the grascale is in a specific range (eg: 210 to 230)
Then convert it to red or blue
So that the air flow will be some colorful line on a grarscale figure.
But I don't know hot to check the pixel and convert them.

Accepted Answer

ME
ME on 6 Nov 2019
This should do the trick:
A = rgb2gray(imread('image.png'));
A = cat(3, A, A, A);
s=size(A);
for i=1:s(1)
for j=1:s(2)
if(A(i,j,1)<=230 && A(i,j,1)>=210)
A(i,j,1:3) = [255 0 0];
end
end
end
It will convert any grayscale sections in the range 210 to 230 to red. You could also add another similar if statement if you wanted to also add an additional condition to make some of it blue.
  4 Comments
ME
ME on 7 Nov 2019
No problem at all. Thanks for accepting my answer and I’m glad I could help.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by