How do I remove the background (specifically the vignette) from this image without removing the particles of sand?

조회 수: 5 (최근 30일)
I am doing research where my goal is to remove out of focus particles of sand, and count in focus particles of sand that I capture in lab. I am currently trying to isolate the objects using imgradient but the vignette hinders the ability to distinguish a gradient. I would like to remove the backround vignette as it disrupts the ability to count the particles. I would appreciate any help!
Here's my code (readPGRaw is code we wrote in order to read in our raw images):
filename= '/Users/sammybuckets/Documents/SandTests/S5_2023-07-18-193451-0000.raw';
ubit= 8;
size= [2448 2048 1];
I = readPGRaw(filename,ubit,size);
figure
G= imgradient(I);
J= G>110;
imagesc(J)
axis image
colormap gray
[JV, JU]= find(J);
hold on
plot(JU,JV,'.')
se = strel('disk',15);
closeJ = imclose(J,se);
[JVC, JUC]= find(closeJ);
plot(JUC,JVC,'.')
plot(JU,JV,'.')
BW2 = imfill(closeJ,'holes');
figure
imshow(BW2)
title('Filled Image')

채택된 답변

Image Analyst
Image Analyst 2023년 7월 25일
Your best bet is to take a separate, blank shot with no particles in the field of view and then divide your particle images by that blank image. Then you can just use a simple fixed global threshold. Attached is a demo.

추가 답변 (1개)

Angelo Yeo
Angelo Yeo 2023년 7월 25일
The function imflatfield can be of help.
I = imread('raw.png');
%% Removing Vignette and binarizing image
sigma = 20;
Iflatfield = imflatfield(I, sigma);
Iflatfield = rgb2gray(Iflatfield);
BW = imbinarize(Iflatfield);
IBW = uint8(zeros(size(BW)));
IBW(~BW) = 255;
%% applying morphologies
J = medfilt2(medfilt2(IBW));
SE = strel('ball',5, 5);
J = imerode(J, SE);
SE = strel('ball', 4, 4);
J = imdilate(J, SE);
%% check results
C = imfuse(I, J,"falsecolor");
imshow(C)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by