What is best way to reduce speckle size?

조회 수: 4 (최근 30일)
Dynamic
Dynamic 2021년 8월 23일
답변: Image Analyst 2021년 8월 24일
I have an image with speckle noise. My question is how to reduce the speckle size rather than speckle noise. Please find the attached image for an example. If you look over the image carefully then you can find the speckle noise with huge size, I want to reduce the size of the speckle.
  댓글 수: 8
Adam Danz
Adam Danz 2021년 8월 24일
As indicated in my comment, it would be fairly easy to accomplish with a single object in the image but with many objects, it much more complicated and I'm not even 100% sure it's possible. By 'a piece of code' I'm assuming you're looking for an entire solution which I don't have (not even conceptually).
You've got yourself a very hard problem if I understand it correctly. The objects in your image are very noise and due to the low resolution, they are represented by just a few pixels in some cases. You can't shrink that.
DGM
DGM 2021년 8월 24일
I added an example of resizing objects. Note the practical limitations.

댓글을 달려면 로그인하십시오.

답변 (2개)

DGM
DGM 2021년 8월 23일
편집: DGM 2021년 8월 24일
Since it's unclear what properties are important, I'll just make something up.
This does the "shrinking" by essentially cropping the edges of each "speckle" area in a mask:
inpict = imread('text_qss.jpg');
% binarize the image using some method to describe what constitutes a "speckle"
%m = imbinarize(inpict,'adaptive','foregroundpolarity','bright','sensitivity',0);
m = inpict>30;
% shrink said mask by one pixel (or more if desired)
ms = bwmorph(m,'shrink',1);
% extract base noise and "shrunk" speckles, combine
basenoise = uint8(double(inpict).*~m); % remove speckles from image
peaknoise = uint8(double(inpict).*ms); % apply shrunk mask to speckles
outpict = basenoise + peaknoise; % combine
ORIGINAL:
MODIFIED:
Alternatively, "shrinking" could be done with a mask to crudely enforce a desired size and shape.
inpict = imread('text_qss.jpg');
% binarize the image using some method to describe what constitutes a "speckle"
m = inpict>30;
% create gaussian mask around each speckle center
S = regionprops(m,inpict,'weightedcentroid');
C = round(vertcat(S.WeightedCentroid));
cm = zeros(size(m));
cm(sub2ind(size(m),C(:,2),C(:,1))) = 1;
f = mat2gray(fspecial('gaussian',5,1)); % pick some radius,sigma
cm = imfilter(cm,f);
basenoise = uint8(double(inpict).*~m); % extract base noise
peaknoise = uint8(double(inpict).*cm.*m); % extract speckles, apply mask
outpict = basenoise+peaknoise; % combine
EDIT:
This is an example of literally resizing objects and cramming them back into an image. This isn't something that would be practical for tiny images where object features are only 1px wide, so I'm using a larger test image. This also would likely destroy the meaningfulness of certain qualities of the image, given that a nonuniform object can no longer fit in its original location. An object with a hole will shrink to occlude background features which were once visible, and it will leave behind an area of empty image where no background features exist.
I made no attempt to place objects according to their centroid or weighted centroid. That would probably also be worth considering. This is just a simplified example.
% this assumes uint8 images, light-on-dark polarity
inpict = imread('sources/speckleseg.png');
m = bwareafilt(inpict>35,5);
objscale = 0.5;
S = regionprops(m,inpict,'subarrayidx','image');
outpict = uint8(double(inpict).*~m); % remove objects from image
for k = 1:numel(S)
% extract a masked copy of this object
thisobj = uint8(double(inpict(S(k).SubarrayIdx{:})).*S(k).Image);
s0 = size(thisobj);
% shrink by scaling factor
thisobj = imresize(thisobj,objscale);
s1 = size(thisobj);
% pad symmetrically with zero
thisobj = padarray(thisobj,ceil((s0(1:2)-s1(1:2))/2),0,'pre');
thisobj = padarray(thisobj,floor((s0(1:2)-s1(1:2))/2),0,'post');
% insert resized object back into output image
outpict(S(k).SubarrayIdx{:}) = outpict(S(k).SubarrayIdx{:}) + thisobj;
end
Like I said, since objects don't fit back into the holes they left in the background, you'll have to decide where they go. If they simply remain centered in their bounding box, the result can very easily change the structure of an image.

Image Analyst
Image Analyst 2021년 8월 24일
I don't have any software for it but a common way to reduce speckle noise is the Knox-Thompson filter. Just Google it. Sorry, I can't help you write the code.
Or see

Community Treasure Hunt

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

Start Hunting!

Translated by