MATLAB Answers

Why the dimensions of my picture in pixels is reduced when I save my image?

4 views (last 30 days)
Hi,
I filter an imageA with a function called bpass and then I display it with imagesc to be able to save it (as .tif). ImageA is 1038*1388 pixels, my filtered image is 1038*1388 double as well, but when I save it (right click on the image, save as...), the picture I then open is 560*420 pixels. Why...?
%Read the image
prepreim = imread('well8 aft.tif');
preim = rgb2gray(prepreim); % Convert uint8 color to uint8 gray scale.
im = double(preim); % Convert to double in the range 0-255.
%spatially filter the image
b = bpass(im,1,4);
figure
colormap gray
imagesc(b)
%save the filtered image
figure, colormap gray, imagesc(b);
set(gca,'xtick',[],'ytick',[]); %remove axis
set(gca,'LooseInset',get(gca,'TightInset')); %remove white band
Not to save it manually, I tried to add the line
saveas(gcf,'8beffilter','tiffn');
But in this case I obtain a picture of dimension 875*656 pixels.
Thank you for your help.

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 3 Feb 2017
That probably saves the whole figure, not the image. Use imwrite() instead to save the image array only.

  6 Comments

Show 3 older comments
Aude Rapet
Aude Rapet on 3 Feb 2017
Here is my initial picture (before applying filter) but I use it in .tif nan .jpg:
My initial image (before filter) is a 1038x1388x3 uint8, then become 1038x1388 uint8 with rgb2gray (second line), then 1038x1388 double with imdouble (third line). b resulting from function bpass is 1038x1388 double.
Here is my code with imagesc and imwrite to save it :
%Read the image
prepreim = imread('well8 aft.tif');
preim = rgb2gray(prepreim); % Convert uint8 color to uint8 gray scale.
im = double(preim); % Convert to double in the range 0-255.
figure
colormap gray
imagesc(im)
whos im
%spatially filter the image
b = bpass(im,1,4);
figure
colormap gray
imagesc(b)
%save the filtered image
figure, colormap gray, imagesc(b);
set(gca,'xtick',[],'ytick',[]);
set(gca,'LooseInset',get(gca,'TightInset'));
imwrite(b,'afterfilter.tif');
Here is my second code where I use imshow :
%%STEP 1 : Read image
original = imread('afterfilter.tif'); %without, t=1 AFTER
figure; imshow(original);
And I send you attached b.mat
Thank you

Sign in to comment.

More Answers (1)

John BG
John BG on 3 Feb 2017
if the bpass function is removing samples to low band pass filter, then the resulting image is going to be smaller.
have you checked that images b and im are same size?
John BG

  2 Comments

Aude Rapet
Aude Rapet on 3 Feb 2017
Yes I checked :
>> whos im
Name Size Bytes Class Attributes
im 1038x1388 11525952 double
>> whos b
Name Size Bytes Class Attributes
b 1038x1388 11525952 double

Sign in to comment.

Sign in to answer this question.