2017-03-29 38 views
0

我的图像是在我用特定尺寸256x256裁剪后的mat文件中,在写入png文件之前大小是正确的。我以png格式保存了它们。现在,我想处理它们,并意识到尺寸不一样,原因是什么?我该如何解决它?由于在修剪和写入PNG文件后,一些图像的大小发生了变化,为什么?

此代码:

[m1,m2] = size(II); 


i1_start = floor((m1)/2)-floor(n/2); % or round instead of floor; using neither gives warning 
i1_stop = i1_start + n; 

i2_start = floor((m2)/2)-floor(n/2); 
i2_stop = i2_start + n; 

B = II(i1_start+1:i1_stop, i2_start+1:i2_stop); 

figure ,imshow(B,[]); 

,这是png格式的转换代码:

outfile = sprintf(png_filename) 
data=uint8(data); 
imwrite(data,outfile,'png','BitDepth' ,8); 
+0

你怎么裁剪图像并保存pngs?请分享您的代码 – drorco

回答

0

使用imwrite功能

A = rand(50); 
imwrite(A,'myGray.png') 
相关问题