how can remove the object that has the maximum distance from center of image?

조회 수: 3 (최근 30일)
sara
sara 2014년 10월 17일
이동: DGM 2023년 2월 12일
if we have some objects in a binary image how can remove the object that has the maximum distance from center of image? for example if this is my image:
how can I obtain this image as result:
thanks
  댓글 수: 4
Guillaume
Guillaume 2014년 10월 17일
By define, I meant tell us what you mean. Is the distance of the object to the centre
  • the distance from the object centroid to the centre?
  • the distance from the furthest point of the object to the centre?
  • the distance from the closest point of the object to the centre?
  • something else?
sara
sara 2014년 10월 17일
편집: sara 2014년 10월 17일
the distance from the closest point of the object to the centre? I mean this.
remove the object that the closest point of the object to center is maximum...

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

답변 (6개)

Matt J
Matt J 2014년 10월 17일
편집: Matt J 2014년 10월 17일
how can I obtain this image as result:
I don't recommend that you use distance as a criterion. It would work, but for the object you've shown, it seems quicker and easier to use solidity,
S=regionprops(Image,'Solidity','PixelIdxList');
[~,idx]=min([S.Solidity]);
Image(S(idx).PixelIdxList)=0;
This is also shift-invariant, whereas the distance criterion is not.
  댓글 수: 9
sara
sara 2014년 10월 18일
편집: sara 2014년 10월 18일
yes I fill this vertically...because 2 lung connect to each other and we don't want this.
Thanks dear Image Analyst I will try this and come back...
Walter Roberson
Walter Roberson 2015년 7월 15일
sara commented "it is good for ELCAP dataset"

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


Matt J
Matt J 2014년 10월 17일
편집: Matt J 2014년 10월 17일
Using distance as the criterion,
L=bwlabel(Image);
[M,N]=size(Image);
[X,Y]=ndgrid((1:M)-M/2-.5,(1:N)-N/2-.5);
distmask=(X.^2+Y.^2).*Image;
idx=L>0;
Lmin=accumarray(L(idx),distmask(idx),[],@min);
[~,idx]=max(Lmin);
Image(L==idx)=0;
  댓글 수: 4
sara
sara 2014년 10월 17일
편집: sara 2014년 10월 17일
thanks Matt
for first code I get a black screen and when I use your second code I have this error
Error using .* Integers can only be combined with integers of the same class, or scalar doubles.
and when I try to change this my result is same as my input...
can you help me why I have this error... I'm confused...
Matt J
Matt J 2014년 10월 17일
The error message would have given you the line number of the error. You should be able to use whos() or the workspace browser to inspect the variables used in that line and see which are integers, which are doubles, etc...

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


Image Analyst
Image Analyst 2014년 10월 17일
sara: Try the attached code (below the image in blue). I basically threshold, do a morphological opening to break away the thin table line, then extract the biggest blob. A snippet:
% Get the binaryImage
binaryImage = grayImage > 135;
% Erode to break away the table from the body
binaryImage = imopen(binaryImage, [1;1;1]);
biggestBlob = ExtractNLargestBlobs(binaryImage, numberToExtract);
It gives the image below:

sara
sara 2014년 10월 19일
Thanks ImageAnalyst and Matt
I think if I remove the top object from my binaryImage maybe my problem solve faster.Dear Matt you said it is easy but I could not write the code for this...so I post this question...when I find the best answer I will come back to this discussion...
Dear ImageAnalyst sometimes the left lung is like a seprated shape and seems to 2 seprate object so all the time biggestblob dose not work... thanks for all of your guidance
  댓글 수: 3
sara
sara 2014년 10월 19일
thanks ImageAnalyst. I think I could not explain my question right.. I show this image :
...if I extract 3 biggest blob left lung damage and if I use imfiil with a big strel : the lesion connect to my lungs...I can not use actvecontour with a high eteration or something like this in perviouse steps because speed of program is important...I hope I could explain my problem ...thank you for all of your helpful guidance.
sara
sara 2015년 1월 22일
편집: sara 2015년 1월 22일
dear image analyst
if we have some objects in an image is there any way to extract 2 objects that are neaerest to each other?? for example
after that I want to have this result:
Is there any way?? thanks

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


Image Analyst
Image Analyst 2015년 1월 22일
Sara, regarding your comment about finding the closest pair of blobs...
"Close" has several definitions. See Hausdorf distance. But let's just assume you want the pair that has the lowest distance between the centroids. Just get the centroids using regionprops() into two arrays centroidx and centroidy. Then calculate the distances, something like
distances = zeros(numberOfBlobs, numberOfBlobs);
for b1 = 1 : numberOfBlobs
for b2 = b1 : numberOfBlobs
distances(b1,b2) = sqrt((centroidx(b1)-centroidx(b2))^2+(centroidy(b1)-centroid(b2))^2);
end
end
Then find the min pair
[blob1, blob2] = find(distances == min(distances(:)));
Then use ismember() to extract those two blobs:
binaryImage = ismember(labeledImage, [blob1, blob2]) > 0;
or something like that. That's just off the top of my head and may need editing.
If this answers your question, can you "Accept" my answer?
  댓글 수: 3
rsnandi
rsnandi 2019년 7월 12일
'hi image analyst..... 'how can I calculate the distance of each entroid from upper border line of image so that I can remove the nearest objects(centroids)) from the above image. thanks
Image Analyst
Image Analyst 2019년 7월 13일
Get the bounding box
props = regionprops(binaryImage, 'BoundingBox');
allBB = vertcat(props.BoundingBox);
% Find just top lines alone.
topLines = allBB(:, 2); % Extract column 2.
% Find out which ones are farther away than some threshold.
keepers = topLines > someLineNumber; % Whatever you want, for example 40.
% Extract out those into a new binary image.
newBinaryImage = ismember(binaryImage, find(keepers));

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


sara
sara 2015년 1월 26일
편집: sara 2015년 1월 26일

thanks ImageAnalyst

I use this code:

    if true
     I =input('enter an image','s');
I=imread(I);
Ibw = im2bw(I);
Ibw = imfill(Ibw,'holes');
Ilabel = logical(Ibw);
stat = regionprops(Ilabel,'centroid');
imshow(I); hold on;
for x = 1: numel(stat)
    plot(stat(x).Centroid(1),stat(x).Centroid(2),'ro');
end

for b1 = 1 : numel(stat)

for b2 = b1 : numel(stat)
distances(b1,b2) = sqrt((stat(b1).Centroid(1)-stat(b2).Centroid(1))^2+(stat(b1).Centroid(2)-stat(b2).Centroid(2))^2)
   end
end

tmp = distances; tmp(tmp == 0) = Inf; % as above

[colminvals, colminrows] = min(tmp); % find min in each column

[minVal, minCol] = min(colminvals) % find overall min and its column

 [blob1, blob2] = find(distances == minVal)

binaryImage = ismember(Ilabel, [blob1, blob2]) > 0;

figure,imshow(binaryImage);

    end

but I could not get the answer...and result is like input can you help me??

  댓글 수: 1
sara
sara 2015년 1월 26일
my result like these
and our endless result is
it is like our input without any changes

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

Community Treasure Hunt

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

Start Hunting!

Translated by