How to divide 6x4 image into 4 equal parts without changing dpi?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a image of 6x4 of 200 dpi, that I need to divide to 4 equal parts of 3x2 each of 200dpi. I have tried the following code, but unfortunately the cropping does not work and dpi changes. Please help. Thank you.
soil=imread('S01-15.tiff');
soil=rgb2gray(soil);
imshow(soil);
title('Original Image','FontSize',11);
lu=soil(1:size(soil,1)/2,1:size(soil,2)/2,:);
ld=soil(size(soil,1)/2+1:size(soil,1),1:size(soil,2)/2,:);
ru=soil(1:size(soil,1)/2,size(soil,2)/2+1:size(soil,2),:);
rd=soil(size(soil,1)/2+1:size(soil,1),size(soil,2)/2+1:size(soil,2),:);
figure,imshow(lu);
figure,imshow(ld);
figure,imshow(ru);
figure,imshow(rd);
댓글 수: 1
Michael Dombrowski
2017년 7월 12일
Since you are just doing matrix manipulation, your code is correct and the dpi can still be 200 dpi since matlab isn't dropping or adding any pixels. Imshow will simply display the matrix as an image with no specific dpi. You can set the dpi if you export the image sections.
Please be more specific, if you can, about what you mean that the dpi is changing.
답변 (1개)
Will Nitsch
2017년 7월 12일
This should do what you are hoping for.
>> Iin = rand(6*200,4*200); %6 inches by 4 inches at 200 pixels per inch
>> size(Iin)
ans =
1200 800
>> I1 = Iin(1:end/2,1:end/2); % top left
>> I2 = Iin((end/2+1):end,1:end/2); % bottom left
>> I3 = Iin(1:end/2,(end/2+1):end); % top right
>> I4 = Iin((end/2+1):end,(end/2+1):end); % bottom right
You can then save the image as a tif file with a resolution (DPI) of 200:
>> imwrite(I1,'I1.tif','Compression','none', 'Resolution',200);
>> imwrite(I2,'I2.tif','Compression','none', 'Resolution',200);
>> imwrite(I3,'I3.tif','Compression','none', 'Resolution',200);
>> imwrite(I4,'I4.tif','Compression','none', 'Resolution',200);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!