Read/Open image from instance of Python io.BufferedReader class
I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader
class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.
# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')
from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"
img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"
I am open to other libraries besides PIL.
UPDATE
The following also fails:
img = Image.open(file)
It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.
python image opencv python-imaging-library google-cloud-dataflow
|
show 5 more comments
I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader
class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.
# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')
from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"
img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"
I am open to other libraries besides PIL.
UPDATE
The following also fails:
img = Image.open(file)
It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.
python image opencv python-imaging-library google-cloud-dataflow
img = Image.open(bufferedreader)
– Kinght 金
Nov 21 '18 at 0:43
Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such asimg_array = np.array(img, dtype=np.uint8)
orimg.show()
I get an error that starts withtempfile.tif: Cannot read TIFF header.
and end withraise IOError(err) IOError: -2
– Ryan Stack
Nov 21 '18 at 1:12
IOError: -2
: Make sure the file exists.os.path.exists(fpath)
– Kinght 金
Nov 21 '18 at 1:19
Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images
– Ryan Stack
Nov 21 '18 at 17:17
ABufferedReader
is for sequential input, so if the TIFF code is trying to seek it's going to fail.
– Mark Ransom
Nov 21 '18 at 17:25
|
show 5 more comments
I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader
class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.
# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')
from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"
img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"
I am open to other libraries besides PIL.
UPDATE
The following also fails:
img = Image.open(file)
It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.
python image opencv python-imaging-library google-cloud-dataflow
I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader
class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.
# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')
from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"
img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"
I am open to other libraries besides PIL.
UPDATE
The following also fails:
img = Image.open(file)
It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.
python image opencv python-imaging-library google-cloud-dataflow
python image opencv python-imaging-library google-cloud-dataflow
edited Nov 21 '18 at 17:09
Ryan Stack
asked Nov 20 '18 at 14:48
Ryan StackRyan Stack
313213
313213
img = Image.open(bufferedreader)
– Kinght 金
Nov 21 '18 at 0:43
Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such asimg_array = np.array(img, dtype=np.uint8)
orimg.show()
I get an error that starts withtempfile.tif: Cannot read TIFF header.
and end withraise IOError(err) IOError: -2
– Ryan Stack
Nov 21 '18 at 1:12
IOError: -2
: Make sure the file exists.os.path.exists(fpath)
– Kinght 金
Nov 21 '18 at 1:19
Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images
– Ryan Stack
Nov 21 '18 at 17:17
ABufferedReader
is for sequential input, so if the TIFF code is trying to seek it's going to fail.
– Mark Ransom
Nov 21 '18 at 17:25
|
show 5 more comments
img = Image.open(bufferedreader)
– Kinght 金
Nov 21 '18 at 0:43
Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such asimg_array = np.array(img, dtype=np.uint8)
orimg.show()
I get an error that starts withtempfile.tif: Cannot read TIFF header.
and end withraise IOError(err) IOError: -2
– Ryan Stack
Nov 21 '18 at 1:12
IOError: -2
: Make sure the file exists.os.path.exists(fpath)
– Kinght 金
Nov 21 '18 at 1:19
Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images
– Ryan Stack
Nov 21 '18 at 17:17
ABufferedReader
is for sequential input, so if the TIFF code is trying to seek it's going to fail.
– Mark Ransom
Nov 21 '18 at 17:25
img = Image.open(bufferedreader)
– Kinght 金
Nov 21 '18 at 0:43
img = Image.open(bufferedreader)
– Kinght 金
Nov 21 '18 at 0:43
Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as
img_array = np.array(img, dtype=np.uint8)
or img.show()
I get an error that starts with tempfile.tif: Cannot read TIFF header.
and end with raise IOError(err) IOError: -2
– Ryan Stack
Nov 21 '18 at 1:12
Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as
img_array = np.array(img, dtype=np.uint8)
or img.show()
I get an error that starts with tempfile.tif: Cannot read TIFF header.
and end with raise IOError(err) IOError: -2
– Ryan Stack
Nov 21 '18 at 1:12
IOError: -2
: Make sure the file exists. os.path.exists(fpath)
– Kinght 金
Nov 21 '18 at 1:19
IOError: -2
: Make sure the file exists. os.path.exists(fpath)
– Kinght 金
Nov 21 '18 at 1:19
Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images
– Ryan Stack
Nov 21 '18 at 17:17
Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images
– Ryan Stack
Nov 21 '18 at 17:17
A
BufferedReader
is for sequential input, so if the TIFF code is trying to seek it's going to fail.– Mark Ransom
Nov 21 '18 at 17:25
A
BufferedReader
is for sequential input, so if the TIFF code is trying to seek it's going to fail.– Mark Ransom
Nov 21 '18 at 17:25
|
show 5 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395564%2fread-open-image-from-instance-of-python-io-bufferedreader-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395564%2fread-open-image-from-instance-of-python-io-bufferedreader-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
img = Image.open(bufferedreader)
– Kinght 金
Nov 21 '18 at 0:43
Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as
img_array = np.array(img, dtype=np.uint8)
orimg.show()
I get an error that starts withtempfile.tif: Cannot read TIFF header.
and end withraise IOError(err) IOError: -2
– Ryan Stack
Nov 21 '18 at 1:12
IOError: -2
: Make sure the file exists.os.path.exists(fpath)
– Kinght 金
Nov 21 '18 at 1:19
Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images
– Ryan Stack
Nov 21 '18 at 17:17
A
BufferedReader
is for sequential input, so if the TIFF code is trying to seek it's going to fail.– Mark Ransom
Nov 21 '18 at 17:25