Converting 3D vector to scalar output

7 ビュー (過去 30 日間)
Maggie
Maggie 2024 年 4 月 12 日
回答済み: Benjamin Thompson 2024 年 4 月 12 日
We're recording RGB values from ImageJ, and each RGB value corresponds to a scalar pH. The ultimate goal is to input an RGB vector, and output the corresponding pH value based on the standardized data. How can we take a 3D vector and convert it to a scalar output? I assume I have to do some sort of PCA or regression model, but I'm not sure how to do that. I have uploaded the file with the RGB values that all correspond to specific pHs (Multiple RGB values can correspond to the same pH).

回答 (2 件)

Samson
Samson 2024 年 4 月 12 日
移動済み: Matt J 2024 年 4 月 12 日
Do you know which pH value each RGB value corresponds to? If you do a lookup table should prove usefull.
Im reducing the total amount of colors to keep it short here... This is by no means the best way of implementing a lookup table, but it can get you started in thinking.
Say the RGB triplet [1,1,0] represents a pH of 8;
We create an array of all rgb triplets
RGB = [ 0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
1 0 1
0 1 1
1 1 1];
We then define a vector of corresponding ph Values
pH = [1
2
4
7
8
9
12];
We find the index in RGB that matches the RGB data from imageJ
imageJ = [1,1,0];
for i = 1:size(RGB,1)
if imageJ == RGB(i,:);
ind = i;
break
end
end
ResultingpH = pH(i)
ResultingpH = 8

Benjamin Thompson
Benjamin Thompson 2024 年 4 月 12 日
You can export your data to CSV and import into MATLAB as a table. Then use this script to review it and get some insight. It is not following any nice pattern in the RGB coordinate space. But if all you want is a pH assignment to the nearest 0.5 value, then you could try calculating the centroid for each color group using the "mean" function. Then assign a pH value from the choices of {4.5, 5.0, ..., 7.5, 8.0} based on which centroid the RGB triplet is closest to.
The centroid is also where I plot the "text" value for each pH group in the attached script. Some are very close together but it might work.

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by