You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

逐帧场景变化的多图像CV计算中非均匀光照问题解决方法咨询

多组荧光图像变异系数计算的光照不均问题

我目前需要计算分析多组图像的变异系数(coefficient of variance, CV)并最终完成组间对比,所用代码如下。

我采用Otsu算法将前景(不同深浅的绿色荧光流体)与背景(深蓝色)分割:低于阈值的像素强度赋值为0,高于阈值的像素保留原始强度,随后计算有效像素的平均强度及对应标准差(STD),用STD除以图像平均强度得到该图像的CV值。每组共15张图像,组内各图像的区域覆盖范围与图案均存在差异。

但当前存在组内及组间图像水平、垂直方向均有非均匀光照的问题,导致CV测量结果异常。我已尝试过imhistmatch、白平衡校正、灰度校正、同态滤波、中值滤波等方法,均因逐帧场景变化无法生效,暂未想到其他可行方案。

注:未拍摄纯背景或纯前景图像,所有图像均同时包含前景与背景。

所用MATLAB代码

fileList = dir('*.jpg');
fileList = {fileList.name};
thr = [];
im = imread(fileList{1});
img = im(:,:,2);
refSize = size(img);
CV = [];
num_of_soil_pixels = [];
num_of_foam_pixels = [];
mean_collect = [];
thr_collect = [];
sum_foam_intensities = [];
std_only =[];

%%%%% Defining circular areas over which calcs occur %%%%%%%%%%%%%
diam = mean(refSize);
%%%%% Iteration process to compute and store CV values for each image %%%%%
for i = 1:length(fileList)
    im = imread(fileList{i});
    fileList{i};
    % Resize images with respect to the first image
    if size(im(:,:,2))~= refSize
            im_resized = imresize(im, refSize);
    else
        im_resized = im;
    end
    % Convert to grayscale
    img = rgb2gray(im_resized);
    % Threshold the image using Otsu
    thr = graythresh(img);
    segmented_img = imbinarize(img, thr);
    out_img = double(img) .* segmented_img;
    % Normalize the image via dividing by the range
    out_img = 255*(out_img - min(min(out_img)))/(max(max(out_img))-min(min(out_img)));
    % Create a circular mask to obtain the region of interest (circle)
    mask = zeros(refSize);
    [xgrid, ygrid] = meshgrid(1:refSize(2), 1:refSize(1));
    mask = ((xgrid-(refSize(1)/2)).^2 + (ygrid-(refSize(1)/2)).^2) <= (diam/2.2).^2;
    
    % compare thresholded image with the RGB version - validate how well
    % Otsu detects the green regions (foreground)
    %fh2 = figure(23);
    %fh2.WindowState = 'maximized';
    %subplot(5,3,i)
    %imshowpair(im_resized,uint8(out_img),'montage')

    % mask the grayscale image
    values = out_img(mask);
    % Calculate the mean
    mymean = mean(values);
    
    % store various variables for plotting purposes
    mean_collect = [mean_collect;mymean];
    thr_collect = [thr_collect;thr*255];
    CV = [CV; std(values)/mymean]; % 原代码stdev未定义,已修正
    std_only = [std_only;std(values)];
    num_of_soil_pixels = [num_of_soil_pixels;sum(values==0)];
    num_of_foam_pixels = [num_of_foam_pixels;nnz(values)];
    sum_foam_intensities =[sum_foam_intensities;sum(values(values~=0))];
end 

figure (1)
plot(CV, 'ok','MarkerfaceColor','g')
ylim([0,4])
xlim([0,15])
grid on

解决方案建议

1. 优化目标通道提取

不要使用rgb2gray转换全图,直接提取图像的G(绿色)通道做后续处理,绿色荧光信号在G通道响应最高,深蓝色背景在G通道响应极低,能直接降低背景干扰,提升分割精度。

2. 无参考自适应光照校正

不需要纯背景图,用大核高斯滤波估计光照背景层:

  • 对单张图的G通道做核大小为51~101像素的高斯模糊(核尺寸需大于你场景中最大的前景连通域尺寸),得到的模糊图就是非均匀光照的背景层
  • 用原始G通道减去该背景层,即可得到抵消了光照不均影响的前景信号图,完美适配逐帧场景变化的情况。

3. 分割算法优化

做完光照校正后,替换全局Otsu为自适应阈值分割(MATLAB用adaptthresh函数),可以适配局部光照差异,分割准确率远高于全局阈值。

4. 归一化逻辑修正

不要对单张图做独立的范围归一化,单张图的最大最小强度波动会直接拉高CV值,改为统计所有组所有图像的前景强度的全局最大值、最小值,所有图像统一用该全局值做归一化,保证组间、组内的强度基准一致。


内容的提问来源于stack exchange,提问作者thelabmaster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 02:06:11