Hello, I need to take a color strip that gives concentration and convert it into a continuos quantitative graph that will give me RGB value vs concentration. The reference colorbar has 6 colors, which correspond to different concentrations. I need to

1 view (last 30 days)
Hello, I need to take a color strip that gives concentration and convert it into a continuous quantitative graph that will give me RGB value vs concentration. The reference colorbar has 6 colors, which correspond to different concentrations. I need to use matlab to convert the RGB values from each color to a graph, where if I know the RGB values of a picture I can determine the concentration. I have converted the reference colorbar to 100x600 pixel image where each color is a 100x100 pixel block that runs in a continuous fashion.
the concentration from left to right are 160,80,40,15,5,0 mg/ml If you could help that would be great.
  3 Comments
Abdul Khan
Abdul Khan on 14 Mar 2016
Edited: Geoff Hayes on 14 Mar 2016
Here is the colorbar with the concentrations going from left to right. I currently have this as my code to extract RGB values for every color:
a=imread(GaplessChart.jpg');
R=a(1,1:600,1);
B=a(1,1:600,2);
G=a(1,1:600,3);
fiugre;hold on
plot(R,'r'); M1='Red Values';
plot(B,'b'); M2='Blue Values';
plot(G,'g'); M3='Green Values';
xlabel 'Horizontal Pixel Location'
ylabel 'Vertical Pixel Location'
legend(M1,M2,M3)
title 'Gapless RBG'
Abdul Khan
Abdul Khan on 14 Mar 2016
Edited: Geoff Hayes on 14 Mar 2016
I want to create a code where I could have a continuous RGB to concentration, because here there are big gaps in concentration.
a=imread(GaplessChart.jpg');
R=a(1,1:600,1);
B=a(1,1:600,2);
G=a(1,1:600,3);
figure; hold on
plot(R,'r'); M1='Red Values';
plot(B,'b'); M2='Blue Values';
plot(G,'g'); M3='Green Values';
xlabel 'Horizontal Pixel Location'
ylabel 'RGB Value'

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Mar 2016
You need to get 6 mean RGB values. So split the image up into channels
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Then get the means
redMeans(1) = mean2(redChannel(:, 1:100));
redMeans(2) = mean2(redChannel(:, 101:200));
redMeans(3) = mean2(redChannel(:, 201:300));
redMeans(4) = mean2(redChannel(:, 301:400));
redMeans(5) = mean2(redChannel(:, 401:500));
redMeans(6) = mean2(redChannel(:, 501:end));
Then you can fit some polynomial through it
coefficients = polyfit(1:6, redMeans, 1); % Fit a line through them.
Now for any arbitrary concentration, you can get the estimated red value of it like:
estimatedRed = coefficients(1) * testConcentration + coefficients(2);
do the same for green and blue.
  1 Comment
Image Analyst
Image Analyst on 14 Mar 2016
All this assumes that the color means lie along a straight line. If they don't you may have to increase the order of the polynomial. By the way, this is not how I'd really do it. And anyway, I'd do the converse. Usually you'd probably have an RGB color and you want to know the concentration, not vice versa like you asked.

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!