我想获得图像的每像素局部对比度,我猜Weber contrast是一个合理的公式。问题是,如何在matlab中得到它,假设我们只使用相邻的像素(例如,5x5)作为Ib?
答案 0 :(得分:2)
要计算局部对比度,我们需要亮度图像和局部背景亮度。
假设我们已经有一个亮度图像,可以通过取局部区域内所有像素的平均值来计算特定像素的局部背景亮度。
我们可以通过在水平和垂直方向上重复移动0:(n-1)像素来收集一组这样的局部背景区域(原始图像中每个像素一个)。
以下演示函数说明了基本概念:
function weberContrastDemo
imgWidthPixels = 1024;
imgHeightPixels = 1024;
localBackgroundSizePixels = 5; % square patch
luminance = randn( imgHeightPixels, imgWidthPixels );
luminance( 496:528, 496:528 ) = 20;
background = localMeanFilter( luminance, localBackgroundSizePixels );
weberContrast = ( luminance - background );% ./ background;
imagesc( weberContrast );
title( 'Weber Contrast' );
colormap(gray);
end
function filteredImg = localMeanFilter( img, regionSizePixels )
offsetImages = getOffsetImages( img, regionSizePixels );
filteredImg = mean( offsetImages, 3 );
end
function buffer = getOffsetImages( img, regionSizePixels )
% GETOFFSETIMAGES
imgSize = size( img );
imgHeight = imgSize( 1 );
imgWidth = imgSize( 2 );
minDelta = 0;
maxDelta = (regionSizePixels-1);
bufferWidth = imgWidth + maxDelta;
bufferHeight = imgHeight + maxDelta;
bufferDepth = regionSizePixels .^ 2;
bufferSize = [ bufferHeight bufferWidth bufferDepth ];
buffer = zeros( bufferSize );
iSample = 0;
for deltaX = minDelta:maxDelta
iStartX = 1 + deltaX;
iEndX = imgWidth + deltaX;
idxX = iStartX:iEndX;
for deltaY = minDelta:maxDelta
iSample = iSample + 1;
iStartY = 1 + deltaY;
iEndY = imgHeight + deltaY;
idxY = iStartY:iEndY;
buffer( idxY, idxX, iSample ) = img;
end
end
iMin = ceil(regionSizePixels/2);
iMax = iMin + (imgWidth-1);
buffer = buffer( iMin:iMax, iMin:iMax, : );
end % GETOFFSETIMAGES
对于真正的心理物理实验,我们希望将参数从弧度或球面度转换为像素,并且需要校准显示器或图像捕获设备,以便亮度测量准确。