Matlab Image Baseline (Offset Removal) Correction

有些话、适合烂在心里 提交于 2021-02-08 07:31:31

问题


I have this plot:

and want to flatten its baseline/reduce offset using Matlab.

Basically like a baseline correction for a spectrum but here I've got a mesh and can't get my head around it how to flatten its baseline when dealing with a matrix? Basically the dot should stay but the surrounding is actually zero. The noise can stay, though.

Here is the image:

I am wondering if something like this works:

        for x=1:1201
        for y=1:1201
             Ibasetest = polyfit(x,y,1);
        end
        end

Simply put do a baseline for each X along Y for Z data. But I can't get it to work. :(


回答1:


Note: Another method to attempt may include moving/windowing averages to calculate the local amount to offset by.

Method 1: Discrete Cosine Transform (DC Offset Removal)

Converts the image into the frequency domain uses the Discrete Fourier Transform (DCT). Removes the DC coefficient in the top-left corner (set to zero) of the matrix and convert it back to the spatial domain using the Inverse Discrete Fourier Transform (IDCT).

Image = imread("Test_Image.jpg");

%Converting image to greyscale if RGB image%
[Image_Height,Image_Width,Depth] = size(Image);
if(Depth == 3)
Image = rgb2gray(Image);
end

%Removing image offset%    
Discrete_Cosine_Transformed_Image = dct2(Image);
Discrete_Cosine_Transformed_Image(1,1) = 0;
Inverse_Discrete_Cosine_Transformed_Image = idct2(Discrete_Cosine_Transformed_Image);

Calibrated_Image = medfilt2(Inverse_Discrete_Cosine_Transformed_Image,[20 20]);

% Plotting the original and thresholded image%
X_Axes = (1:1:Image_Height);
Y_Axes = (1:1:Image_Width);

subplot(1,2,1); surf(X_Axes,Y_Axes,Image,'EdgeColor','none');
title("Original Image Plot");
xlabel('X-Axis'); ylabel('Y-Label');
zlim([0 255]);

subplot(1,2,2); surf(X_Axes,Y_Axes,uint8(Calibrated_Image),'EdgeColor','none');
title("Calibrated Image Plot");
xlabel('X-Axis'); ylabel('Y-Label');
zlim([0 255]);

Key Discrete Cosine Transform (DCT) Filtering Code Lines

%Removing image offset%    
Discrete_Cosine_Transformed_Image = dct2(Image);
Discrete_Cosine_Transformed_Image(1,1) = 0;
Inverse_Discrete_Cosine_Transformed_Image = idct2(Discrete_Cosine_Transformed_Image)

Method 2: Standard Uniform Offset (no-tilt accommodation)

Uses a constant value and subtracts that across the whole image matrix.

Test Image 1: Using Lowest Intensity to Calculate Offset

Test Image 2: Using Average/Mean to Calculate Offset

Image = imread("Circular_Image.png");

%Converting image to greyscale if RGB image%
[Image_Height,Image_Width,Depth] = size(Image);
if(Depth == 3)
Image = rgb2gray(Image);
end

   %Removing image offset%
Lowest_Intensity_Value = min(Image,[],'all');
Average = mean(Image,'all');
Calibrated_Image = Image - Average;

% Plotting the original and thresholded image%
X_Axes = (1:1:Image_Height);
Y_Axes = (1:1:Image_Width);

subplot(1,2,1); surf(X_Axes,Y_Axes,Image,'EdgeColor','none');
title("Original Image Plot");
xlabel('X-Axis'); ylabel('Y-Label');
zlim([0 255]);

subplot(1,2,2); surf(X_Axes,Y_Axes,Calibrated_Image,'EdgeColor','none');
title("Calibrated Image Plot");
xlabel('X-Axis'); ylabel('Y-Label');
zlim([0 255]);

Using MATLAB version: R2019b



来源:https://stackoverflow.com/questions/64218701/matlab-image-baseline-offset-removal-correction

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