Histogram normalization for normalizing background changes

谁说我不能喝 提交于 2019-12-25 04:29:26

问题


I recorded a sequence of depth images using Kinect v2. But the background brightness is not constant. But It keeps changing from dark to light and light to dark (i.e)

.
So I was thinking to use Histogram normalization of each image in a sequence to normalise the background to the same level. Can anyone please tell me how I can do this?

回答1:


Matlab has a function for histogram matching and their site has some great examples too

Just use any frame as the reference (I suggest using the first one, but there is no real reason to do so), and keep it for all the remaining frames. If you want to decrease processing time you can also try lowering the number of bins. For a uint8 image there are usually 256 bins, but as you'll see in the link reducing it still produces favorable results

I don't know if kinect images are rgb or grayscale, for this example Im assuming they are grayscale

kinect_images = Depth;
num_frames = size(kinect_images,3); %maybe 4, I don't know if kinect images
                                    %are grayscale(3) or RGB(4)

num_of_bins = 32;

%imhistmatch is a recent addition to matlab, use this variable to 
%indicate whether or not you have it
I_have_imhistmatch = true;

%output variable
equalized_images = cast(zeros(size(kinect_images)),class(kinect_images));

%stores first frame as reference
ref_image = kinect_images(:,:,1);   %if rgb you may need (:,:,:,1)
ref_hist = imhist(ref_image);

%goes through every frame and matches the histof
for ii=1:1:num_frames
    if (I_have_imhistmatch)
        %use this with newer versions of matlab
        equalized_images(:,:,ii) = imhistmatch(kinect_images(:,:,ii), ref_image, num_of_bins);
    else
        %use this line with older versions that dont have imhistmatch
        equalized_images(:,:,ii) = histeq(kinect_images(:,:,ii), ref_hist);
    end
end

implay(equalized_images)


来源:https://stackoverflow.com/questions/30908572/histogram-normalization-for-normalizing-background-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!