How to divide 6x4 image into 4 equal parts without changing dpi?

조회 수: 1 (최근 30일)
Tinna Armasamy
Tinna Armasamy 2017년 7월 5일
답변: Will Nitsch 2017년 7월 12일
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
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
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);

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by