2D filter increases saved file size

조회 수: 10 (최근 30일)
bb
bb 2011년 11월 2일
이동: Rena Berman 2023년 12월 28일
I have a question regarding spatial filtering... In the following (greatly) downsized example,
a = y0(1:100,1:2,1);
a = reshape(a,10,10,2);
r = zeros(size(a));
F = fspecial('gaussian');
for i = 1:2
r(:,:,i) = filter2(F,a(:,:,i));
end
save('r.mat','r')
save('a.mat','a')
the saved file a.mat has size 1Kb; and r.mat (2Kb). What leads to the increase in file size? (both 'a' and 'r' has the same dim and uses the same wrkspace memory).
Thanks!

채택된 답변

Image Analyst
Image Analyst 2011년 11월 2일
I can pretty much guarantee that it doesn't take any more time to load a 1 kb file than a 2 kb file. Your disk reading software has a cache size of at least 8 KB of memory (<http://en.wikipedia.org/wiki/Disk_buffer>) so it sucks up a whole sector on disk in one shot. Anything in that sector gets read so it doesn't matter if it's 1 byte or 8000 bytes - it all takes the same amount of time.
But it looks to me like y0 is probably a uint8 color image. Am I right? So that would be 1 byte per element, while r would be a double image with 8 bytes per element. You think that might have something to do with it?
  댓글 수: 1
bb
bb 2011년 11월 2일
well when its 500Mb vs 100Mb it makes a big difference. But you are spot on with the uint8. Did not realize there was a uint8 - double in the read-in procedure.
thanks everyone who helped!

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Image Analyst
Image Analyst 2011년 11월 2일
If you think about it you'll realize why the filtered image is bigger. The filter will "touch" the edge of the image even when the center of the filter is outside the bounds of the image. If you want filter2() to crop it to the same size, you can pass it the 'same' option.
  댓글 수: 2
Jan
Jan 2011년 11월 2일
@bb: If you have a question concerning the command filter2, "help filter2" and "doc filter2" are very recommended. The documentation is written to solve such questions.
bb
bb 2011년 11월 2일
이동: Rena Berman 2023년 12월 28일
Thanks for the quick reply.
However, "r" and "a" do have the same size (as a variable) and take up the same memory space.
size(r) = 10 10 2
size(a) = 10 10 2
It is the saved ".mat" files that take up different hard disk space, and passing 'same' (default for filter2) did not rectify that.

댓글을 달려면 로그인하십시오.


Jan
Jan 2011년 11월 2일
Does a have the type double?
MAT files are compressed, if they are saved in the v7.3 style. Then the compression of a.mat has been more efficient than the compression of r.mat. But this shouldn't affect your work in any way.
  댓글 수: 2
bb
bb 2011년 11월 2일
thanks for reply!
both a and r are double.
they are also saved in the same way (not in v7.3)
right now at this size they do not affect my workflow but they are unfortunately usually much much larger and it can take up to 5x more time to load filtered variable into the workspace.
Image Analyst
Image Analyst 2011년 11월 2일
I have my doubts. What does it say if you issue this command:
class(a)

댓글을 달려면 로그인하십시오.


Bjorn Gustavsson
Bjorn Gustavsson 2011년 11월 2일
Then this puzzles me a bit. In my case filtered images have less noise and compress better. Are your image a synthetic, or even binary with a sparse number of non-zero pixels? If so, then the filtered image might have more non-zero pixels.
If the loading (and saving) of your filtered images takes longer time than it woudl take to load and filter the original image then you might as well just not save the processed images, but rather preprocess them on the fly as needed.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by