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 CenterFile Exchange에서 Dimensionality 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