How to convrt parts of grayscale to RGB

1 次查看(过去 30 天)
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.

采纳的回答

ME
ME 2019-11-6
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 个评论
Yubin ZHONG
Yubin ZHONG 2019-11-7
Oh my first time use mathwork,,,, didnt notice that
ME
ME 2019-11-7
No problem at all. Thanks for accepting my answer and I’m glad I could help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by