
How do I remove the background (specifically the vignette) from this image without removing the particles of sand?
4 次查看(过去 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')
0 个评论
采纳的回答
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
2023-7-25
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!