我们建立了能够产生检测物浓度与颜色对应图表的工具。产生的颜色图表可以被存储在APP或者打印出来,这样我们能够方便地同时量化两种检测物。
1.读入图像
2.找到标准反应区域的中心
3.分别计算反应区域的RGB
4.双线性插值法得到渐变图像。
%initialize
close all
clc
RGB = imread( 'test.jpg' );
ion1='As'; ion2='IPTG';
ion1concentration=[0,0.2,0.4]; ion2concentration=...
[0,0.1,0.2];
ion1num=size(ion1concentration,2);
ion2num=size(ion2concentration,2);
fprintf('%s have %.0f ranks,%s have %.0f\n ranks',ion1,ion1num,ion2,ion2num)
%% mark standard area, calculate RGB and output ion1num*ion2num matrix
R = im2double(RGB( :, :, 1 ));
G = im2double(RGB( :, :, 2 ));
B = im2double(RGB( :, :, 3 ));
StandardArea = [200,200,100;500,200,100;800,200,100;...
200,500,100;500,500,100;800,500,100;...
200,800,100;500,800,100;800,800,100];
% marker = insertShape(RGB,'circle',StandardArea,'LineWidth',5 ,...
% 'Color', 'red','Opacity',0.7) %mark
[m,n]=size(StandardArea);
StandardRadius=StandardArea(1,3);
StandardCenter=StandardArea(:,1:2);
AverageR=zeros(m,1);AverageG=zeros(m,1);AverageB=zeros(m,1);
for i=1:m %For every area
k=0;AllR=0;AllG=0;AllB=0;
for x=(StandardCenter(i,1)-StandardRadius):(StandardCenter(i,1)+StandardRadius)
for y=(StandardCenter(i,2)-StandardRadius):(StandardCenter(i,2)+StandardRadius)
if sqrt((x-StandardCenter(i,1))^2+(y-StandardCenter(i,2))^2)
AllR = AllR + R(x,y);
AllG = AllG + G(x,y);
AllB = AllB + B(x,y);
k=k+1;
end
end
end
AverageR(i) = AllR/k;
AverageG(i) = AllG/k;
AverageB(i) = AllB/k;
end
%% Print Standard Color Chart
AverageR=im2uint8(AverageR);
AverageG=im2uint8(AverageG);
AverageB=im2uint8(AverageB);
reshape(AverageR,ion1num,ion2num)
reshape(AverageG,ion1num,ion2num)
reshape(AverageB,ion1num,ion2num)
Im(:,:,1)=AverageR;
Im(:,:,2)=AverageG;
Im(:,:,3)=AverageB;
I=imresize(RGB,[1080 1920]);
imshow(I);