1
votes

Do someone know how to crop the image in matlab but the crop image result should be square?? so , width and height should be the same size.. thank you..

im=dicomread('078tm.L.dcm');
A=double(im);
B = A/max(A(:));
crop= imcrop(B);
[w h]=size(crop);
 if w~=h
     sizew=w;
     sizeh=h;
     if sizew > sizeh || sizeh < sizew
         w=sizew-sizeh
     else
         h=sizeh-sizew
     end
 end

crop2= imcrop(B,[crop(1) crop(2) w h]);

dicomwrite(crop2, 'a.dcm');

i don't think is right , because i dont know how to get the position image crop.

2
Yes. But first show us what you have tried. - Dan

2 Answers

0
votes

try this

 [crop rect] = imcrop(B); % interactively crop
 if rect(3) ~= rect(4), % not square
    c = rect(1:2) + .5*rect(3:4); % center
    w = min( rect(3:4) ); % take min dimension
    rect = [ ceil(c-.5*[w w]), w, w ];
    crop = imcrop( B, rect ); % re-crop
 end 
0
votes

I guess that your problem is the coordinate system of the figures in Matlab. You can find more information is this link.