From: Matt on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <160bab78-0cd4-485c-a2f3-84a1b6cb61de(a)h12g2000vbd.googlegroups.com>...
> What is the data type? What does it say when you use the "whos"
> command? It needs to be an integer not a floating point array. A
> small image like that should write out in just a few seconds, not a
> minute, if it were uint8. Probably your array is a double. Scale it
> to 0-255 and cast it to uint8 and see if that works.

Thanks -- good catch. My "image" was an array of doubles. That said, the command

imwrite(uint8(I),fname,'bmp');

is still generating a very large 8-bit file -- which is very slow. Can I force to write a binary image? I need to perform this operation ~100,000 times, so every second counts.
From: ImageAnalyst on
I don't know if it can be sped up. Writing 300 gigabytes of data will
take a long time! I doubt imwrite can be sped up any. Maybe try to
see if you can start with uint8 data earlier in the process so you
don't have to cast it, but that won't be possible if you're doing
processes that require floating point precision. Are you sure you
really need to write out 100,000 3 MB images? 3 MB for an image is
not "very large" by the way, in fact a 3 MB digital camera resolution
would be considered "small." But 100,000 of them is a LOT of images.
From: Steve Eddins on
Matt wrote:
> ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message
> <0e5b2491-45b2-45d6-a684-5ec8771179ad(a)k19g2000yqc.googlegroups.com>...
>> On Jan 28, 9:59 pm, "Matt " <m...(a)email.com> wrote:
>> > Hi -- I have a 2D array of ones and zeros and would like to write it
>> as a binary bitmap. Seems simple, but I can't figure out how. What am
>> I missing? Thanks.
>> ---------------------------------------------------------------------------------------------------
>>
>> Matt:
>> You're missing the Image Processing Toolbox. In that toolbox is the
>> imwrite() function, which can write BMP format images in a variety of
>> bit depths.
>
> Thanks for the reply -- I have the IPT, but when I just imwrite(M),
> where M is my matrix, the operation takes a very long time (~1 min for a
> 2000x1600 image). I suspect there is a better option?

One point of clarification: The functions imwrite, imread, and imfinfo
are in MATLAB. They do not require Image Processing Toolbox.

About performance - on my 3.5-year-old IBM Thinkpad T60 laptop with a
slow-ish hard drive, I can write a 2000-by-1600 binary image,
represented as a logical matrix, to a BMP file in about 0.7 seconds. I
can write a 2000-by-1600 grayscale image, represented as a double
matrix, to a BMP file even faster, in about 0.2 seconds.

So I suspect that maybe something else in your code, rather than the
call to imwrite, is taking a minute. Can you post a specific code
fragment that takes a minute, and can you show us how you timed it?

---
Steve Eddins
http://blogs.mathworks.com/steve/
From: Matt on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <6242984d-dfc1-48cc-a0e2-a602f913d4fa(a)o9g2000yqa.googlegroups.com>...
> I don't know if it can be sped up. Writing 300 gigabytes of data will
> take a long time! I doubt imwrite can be sped up any. Maybe try to
> see if you can start with uint8 data earlier in the process so you
> don't have to cast it, but that won't be possible if you're doing
> processes that require floating point precision. Are you sure you
> really need to write out 100,000 3 MB images? 3 MB for an image is
> not "very large" by the way, in fact a 3 MB digital camera resolution
> would be considered "small." But 100,000 of them is a LOT of images.

Thanks again. Yes, I agree that 3 MB is not large in relative terms. What I meant to say is that it is very large relative to the amount of information it needs to contain. My array is nominally 1600 x 2000 and contains nothing but 1s and 0s. If I could save it as a binary image, the size would be reduced by a factor of 8 -- and writing the file to disk would be much faster.
From: ImageAnalyst on
Matt:
Maybe you can save them as .mat files (no pun intended) if no other
program needs to read them in. I haven't used "sparse" matrices but
the capability is there in MATLAB if you want to learn about it.
Maybe that will help reduce the amount of data that actually gets
written out to the .mat file.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: smooth3
Next: Lowpass Butterworth Filter