Filter löschen
Filter löschen

How to crop an ultrasonography to remove annotations and the black portions?

2 Ansichten (letzte 30 Tage)
I have a dataset of ~1350 images with the size 646x618x3.
I dont't know how to crop the image as good as possible in an automatic manner.
I thaught of removing each line untill i have ~0 pixel value but it does not work.
I tried to crop by trying differet velues but some images are shifted/ translated so it does not work a single cropping value for all.
I just need an ideea to implement the code, or some lines if possible!
Thank you!
  1 Kommentar
DGM
DGM am 18 Mär. 2024
Unless you post images, nobody knows what you're actually trying to do. All we know is the size of the image and that you want to crop or fill parts of it. We know there are inconsistencies in the images, but we don't know what they are.
Attach representative images -- enough to describe the portions you want to keep, the portions you want to remove, and how the positions vary between images.
Here is perhaps one tangentially related answer:
... though that's probably not super helpful.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Udit06
Udit06 am 18 Mär. 2024
Bearbeitet: Udit06 am 18 Mär. 2024
Hi Ostache,
You can use edge detection or thresholding to identify the content boundaries and then crop accordingly. This method can adapt to variations in content positioning and size across image. Here is the code implementation for the same.
A = imread("saturn.png");
imshow(A)
grayImg = rgb2gray(A);
edges = edge(grayImg, 'Canny');
% For edge-detected image, you might need to fill in gaps first
filledImg = imfill(edges, 'holes');
% Find connected components
props = regionprops(filledImg, 'BoundingBox');
% Assuming the largest connected component is your content
[~, indexOfMax] = max(arrayfun(@(x) prod(x.BoundingBox(3:4)), props));
boundingBox = round(props(indexOfMax).BoundingBox);
croppedImg = imcrop(A, boundingBox);
imshow(croppedImg)
You can similarly use Otsu's thresholding method, instead of edge detection to find the main region of interest and crop accordingly.
Refer to the following MathWorks documentation to understand more about the functions used in the above code snippet.
I hope this helps!
If this approach does not works with the images that you have, it would be better if you could upload a sample image with this question. It would help others to respond to your query in a better way.

Kategorien

Mehr zu Get Started with Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by