How to convrt parts of grayscale to RGB

1 visualizzazione (ultimi 30 giorni)
Yubin ZHONG
Yubin ZHONG il 6 Nov 2019
Commentato: ME il 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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by