Cropping DICOM image to exact size
Show older comments
I have a large batch of DICOM images that I'm pre-processing for use in a convolutional neural network (for classification). Part of this pre-processing involves segmentating the images to a smaller exact size around the area of interest in the scan, keeping all of these segmentations the same size. Essentially, I want to just crop a 128x128 square out of each image, manually selecting where this square is each time.
It seems like a simple enough thing to do but I'll be working with a lot of images so I'm really just looking for suggestions and pointers to help me develop a method to do this efficiently.
Thanks in advance for your help!
Accepted Answer
More Answers (1)
Image Analyst
on 13 Feb 2018
I'd probably call rbbox() and then determine the center of what they drew, then find the edges by subtracting and adding 14 to the center of the box (rounding the result of course). Then use indexing to extract the cropped region.
Here's a snippet where I use rbbox() in one of my demos:
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca,'CurrentPoint'); % button up detected
point1 = point1(1,1:2); % extract x and y
point2 = point2(1,1:2);
p1 = min(point1,point2); % calculate locations
offset = abs(point1-point2); % and dimensions
% Find the coordinates of the box.
xCoords = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)];
yCoords = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)];
x1 = round(xCoords(1));
x2 = round(xCoords(2));
y1 = round(yCoords(5));
y2 = round(yCoords(3));
width = x2-x1;
height = y2-y1;
% The box from rbbox() disappears after drawing, so redraw the box over the image.
hold on
axis manual
plot(xCoords, yCoords, 'b-'); % redraw in dataspace units
You'll need to do it slightly differently to make sure you have 128x128 cropped regions. If you can't figure it out, write back.
1 Comment
Cameron Harris
on 13 Feb 2018
Categories
Find more on DICOM Format in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!