# Single image import from stack via FTP connection

Background

I would like to create a CDF document that is embedded on a webpage. The CDF will contain some image display elements and upon pressing a button a specific image from an image stack will be displayed. The data will be located on a FTP server where the images are loaded from. Unfortunately, I cannot provide access to the FTP since it is protected with password.

The problem

To speed up the process of importing single images from a stack I came across the option "ImageList" for Import:

Import["R:\\...Largetest1.1.tif", {"ImageList", 5}]


which does exactly what I want. It directly imports only the fifth image of the image stack. My test stack here is located on a local hard drive and contains 101 images of image dimensions 600x1000 pixels. The file size is about 118 MB. I checked for AsboluteTiming when importing the single image from the stack compared to the complete import. Depending on the current CPU load the timings differ a little bit.

First@AbsoluteTiming@Import["R:\\...Largetest1.1.tif", {"ImageList", 5}]


0.060000

First@AbsoluteTiming@Import["R:\\...Largetest1.1.tif"][[5]]


2.426500

Since the Import option works fine for image stacks on the local hard drive I want to use the same option when importing the same image via FTP. Unfortunately, this takes like forever which suggests that it doesn't import only a single image but rather the complete stack and then takes out the fifth image:

First@AbsoluteTiming@Import["ftp://...Largetest1.1.tif", {"ImageList", 5}]


242.915000

When I import a single image via FTP it works quite fast:

First@AbsoluteTiming@Import["ftp://...5Largetest1.1.tif"]


0.120000

Attemps

I then tried to find out what is happening and came across the function ImageReadTIFF. It seems to be possible to also specify import of a single image from a stack. However, the function fails when importing via FTP:

AbsoluteTiming@ImageImportExportDumpImageReadTIFF["R:\\...Largetest1.1.tif", {5}]


{0.070000, {Image}}

AbsoluteTiming@ImageImportExportDumpImageReadTIFF["ftp://...Largetest1.1.tif", {5}]


{0., {{\$Failed, 1}}}

Edit Unfortunately, this is also an issue when importing a single file from compressed archives such as ZIP. I tried to pack the single TIFF files from the above mentioned stack into a ZIP archive and then checked whether importing a single file works when the ZIP file is on my local hard drive and on the FTP server. The file size is reduced to about 36 MB upon compression compared to the 118 MB of the original image stack.

First@AbsoluteTiming[Import["R:\ ... .zip", "Image5.tif"]]

0.160000

First@AbsoluteTiming[Import["ftp://... .zip", "Image5.tif"]]

23.970000

It still semms to download the complete ZIP file first and then accesses the image when importing from FTP.

Questions

• Is there a fast way to import a single image form a stack via FTP? I mean, importing only one image of about 1 MB instead of importing the whole stack of 118 MB and then having to wait until the whole data is transferred.

• Is there a possible workaround I could use such that I do not have to import complete files or archives?

• Is it even possible to do such an import via FTP?

No solution but

After talking to some guys who know more about FTP protocols, I learned that the FTP protocol doesn't allow such operations. It is indeed necessary to download the whole ZIP/TIFF file and then access single files within the file afterwards. Unfortunately, I will have to find another solution for that. Anyhow, thanks for comments and ideas.

-
This isn't an answer to your question, but I don't think you can import anything into a CDF file... –  rm -rf Nov 1 '13 at 9:50
@rm-rf: I checked for that and it worked ;) At least when importing via FTP. –  g3kk0 Nov 1 '13 at 10:04
Interesting... This opens up some possibilities :) btw, you're using the free and not the professional version, right? –  rm -rf Nov 1 '13 at 10:09
Yes I am using the free version. –  g3kk0 Nov 1 '13 at 10:12
@rm-rf That's a backdoor for user input! Shhhh –  belisarius Nov 1 '13 at 11:47