Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Tinna Armasamy
Tinna Armasamy am 5 Jul. 2017
Beantwortet: Will Nitsch am 12 Jul. 2017
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 Kommentar
Michael Dombrowski
Michael Dombrowski am 12 Jul. 2017
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Will Nitsch
Will Nitsch am 12 Jul. 2017
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);

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by