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
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