Automatically trim/remove/crop black borders/margins from images / volumes

18 ビュー (過去 30 日間)
Eric Diaz
Eric Diaz 2014 年 5 月 3 日
コメント済み: lt c 2022 年 2 月 24 日
Is there any way to easily and efficiently automate "trimming / removing / cropping" of "black / 0", "borders / margins" from "images / volumes" in Matlab?
In particular, I am working with 3D volumes and even 4D volumes of medical image datasets, in which the CT or MR reconstruction algorithms occasionally leave a geometric, contiguous, unused, black margin around the images.
For purposes of doing image analysis and statistics, it helps to remove this useless, spurious, zero data which tends to be problematic and contaminating when performing image analysis.
  5 件のコメント
Eric Diaz
Eric Diaz 2014 年 5 月 14 日
編集済み: Eric Diaz 2014 年 5 月 15 日
Can anyone else help with this problem? It seems that everyone yet has given up or is no longer interested in helping.
Image Analyst
Image Analyst 2014 年 5 月 16 日
Or is just too busy at the moment to spend the time needed.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2014 年 5 月 3 日
Get the black pixels imageArray == 0. Then invert and call imclearborder and subtract or XOR the two to get only those black pixels touching the border. Then use that mask to set the pixels to the desired gray level imageArray(mask) = desiredGrayLevel.
  32 件のコメント
Eric Diaz
Eric Diaz 2014 年 5 月 17 日
That is a solution that works. I like it.
I think I have just figured out how to fuse the two solutions to beta solution which works best for me.
I can use the aggressive crop to retain main body and perform means clustering on that subset of images. And I can use the above, XOR solution to perform noise estimation on just the useful pixels.
The additional problem, which I needed to address was the degrees of freedom when performing clustering.
Thanks for your help and suggestions, Image Analyst.
lt c
lt c 2022 年 2 月 24 日
mask = grayImage > 300; % Mask is bright stuff.
% Fill in the body
mask = imfill(mask, 'holes'); % Mask is whole solid body.
% OR it in with the zeros
mask = mask | (grayImage == 0); % Mask now includes pure zeros.
% Extract pixels that are not masked
darkNonZeroOutsidePixels = grayImage(~mask);
Quick question:
I ran code above and get a column vector (darkNonZeroOutsidePixels). Does it mean to be a part of 2D image (without the middle bright and the 0 value edge)?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDetection についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by