How to decode my tiff pictures to input tensorflow using pipline? - batch-file
I am trying to train a neural network using my own tiff pictures with tensorflow pipline. Here is the problem: tensorflow only has 4 kinds of pictures which can be decoded(decode_jpeg, decode_bmp, decode_gif, decode_png), there is no way to decode tiff pictures. So, how can i decode my tiff pictures to use tensorflow pipline to input my own data? or how can i decode my tiff pictures to use batch?
Try this: tfio.experimental.image.decode_tiff.
tfio.experimental.image.decode_tiff(
contents, index=0, name=None
)
contents: A Tensor of type string. 0-D. The TIFF-encoded image.
index: A Tensor of type int64. 0-D. The 0-based index of the frame inside TIFF-encoded image.
name: A name for the operation (optional).
Related
How to convert a 2D numpy array to an tensorflow array for image prediction
Is there an easy way to convert a 2D numpy array to a tf array for image prediction? Currently I have a greyscale image that I have to import into python using another API which gives me a 2D numpy array of pixel values. I then have to save this array as an image and reimport the image in tensorflow so I basically end up with the following: npArray = np.random.rand(100,100) plt.imsave('image.png', npArray, cmap='Greys') imgTf = tf.keras.utils.load_img( 'image.png', target_size=(100, 100) ) imgTfArray = tf.keras.utils.img_to_array(imgTf) imgTfArrayBatch = tf.expand_dims(imgTfArray, 0) # Create a batch This then continues on to feed the image to a trained model and return a prediction. ideally I want to just be able to feed the npArray in rather than having to save a file and open a file but the numpy array is 2D whilst the opened image is a 3D array. Is there a way to easily convert?
Turns out the issue is tensorflow wants an RGB image so you have to fake it when using greyscale. The solution is to stack the array 3 times to represent the 3 RGB channels. npArray = np.stack([npArray, npArray, npArray], axis=2) Once you have done this you can feed it through imgArray = tf.expand_dims(npArray.astype(dtype='float32'), 0) # Create a batch Then feed it into a tf lite classification and it should all work fine.
create a picture shape from an array
I am trying to find an example, or documentation, on creating a picture (floating shape object) inside the Excel sheet. The source is supposed to be a numeric bitmap data, stored in a VBA array acquired using external I/O libraries. Using Excel cells as an intermediary storage is possible, but not desired, since the RGB bitmap data is expected to be huge. The task itself seems to be extremely simple in matlab-like environments, or python. But I just have no Idea how to make it in Excel and VBA without importing an independent image file from the file system.
In terms of storing the file, how huge is 'huge'? If you convert the image into Base64, it'll be a fairly trivial task to split it up amongst the cells and then reconstitute it when converting it into an image. Alternatively, you can store the Base64 string in a standard module - I'm currently doing much the same thing, but my image only clocks in at 100kb (better to save it as a PNG rather than BMP). In terms of converting the Base64 string to an image, the Windows Image Acquisition COM object will convert a byte array into a stdPicture image type (and further to my point above, it will also accept PNG files...]. The following function accepts a Base64 string, converts it into a byte array, and returns an stdPicture object: Function Base64toStdPicture(ByVal Base64Code As String) As StdPicture Dim ImgVector As Object Dim Node As Object Set ImgVector = CreateObject("WIA.Vector") Set Node = CreateObject("Msxml2.DOMDocument.3.0").createElement("base64") Node.DataType = "bin.base64" Node.Text = Base64Code ImgVector.BinaryData = Node.nodeTypedValue Set Base64toStdPicture = ImgVector.BinaryData.Picture Set Node = Nothing Set ImgVector = Nothing End Function From that point, you can out it in an image control, or copy it to / from the clipboard, etc.
Converting RGB data into an array from a text file to create an Image
I am trying to convert txt RGB data from file.txt into an array. And then, using that array, convert the RGB array into an image. (RGB data is found at this github repository: IR Sensor File.txt). I am trying to convert the .txt file into an array which I could use the PIL/Image library and convert the array into an Image, and then put it through the following script to create my image. My roadblock right now is converting the arrays in file.txt into an appropriate format to work with the Image function. from PIL import Image import numpy as np data = [ARRAY FROM THE file.txt] img = Image.fromarray(data, 'RGB') img.save('my.png') img.show() The RGB data looks like as follows, and can also be found at the .txt file from that github repository linked above: [[(0,255,20),(0,255,50),(0,255,10),(0,255,5),(0,255,10),(0,255,25),(0,255,40),(0,255,71),(0,255,137),(0,255,178),(0,255,147),(0,255,158),(0,255,142),(0,255,163),(0,255,112),(0,255,132),(0,255,137),(0,255,153),(0,255,101),(0,255,122),(0,255,122),(0,255,147),(0,255,66),(0,255,66),(0,255,30),(0,255,61),(0,255,0),(0,255,0),(0,255,40),(0,255,66),(15,255,0),(0,255,15)], [(0,255,40),(0,255,45),(15,255,0),(20,255,0),(10,255,0),(35,255,0),(0,255,5),(0,255,56),(0,255,173),(0,255,168),(0,255,153),(0,255,137),(0,255,158),(0,255,147),(0,255,127),(0,255,117),(0,255,142),(0,255,142),(0,255,122),(0,255,122),(0,255,137),(0,255,137),(0,255,101),(0,255,66),(0,255,71),(0,255,61),(0,255,25),(0,255,25),(0,255,61),(0,255,35),(0,255,0),(35,255,0)], [(0,255,15),(0,255,25),(51,255,0),(71,255,0),(132,255,0),(101,255,0),(35,255,0),(0,255,20),(0,255,91),(0,255,153),(0,255,132),(0,255,147),(0,255,132),(0,255,158),(0,255,122),(0,255,132),(0,255,142),(0,255,158),(0,255,122),(0,255,137),(0,255,142),(0,255,147),(0,255,101),(0,255,101),(0,255,86),(0,255,86),(0,255,50),(0,255,45),(0,255,50),(0,255,56),(0,255,30),(56,255,0)], [(0,255,45),(0,255,10),(76,255,0),(127,255,0),(132,255,0)]]
I think this should work - no idea if it's decent Python: #!/usr/local/bin/python3 from PIL import Image import numpy as np import re # Read in entire file with open('sensordata.txt') as f: s = f.read() # Find anything that looks like numbers l=re.findall(r'\d+',s) # Convert to numpy array and reshape data = np.array(l).reshape((24,32,3)) # Convert to image and save img = Image.fromarray(data, 'RGB') img.save('result.png') I enlarged and contrast-stretched the image subsequently so you can see it!
MATLAB - save image in structure array array{i,y} and retrieve with (image(i,y))?
My system: Windows 8.1 MATLAB2015a My issue: When I save a JPG image in a structure array, in this case stiAll{i,y} fileName = strcat('group_',strGr,'_',strVal,'.jpg'); fileNameStr = char(fileName); stiAll{i,y} = imread(fileNameStr); and I try to retrieve the saved image with image(stiAll(i,y)) I get the following error message from MATLAB: Invalid datatype for Image CData. Numeric or logical matrix required for image CData. If I save the image without the {i,y} suffix, so that the image is saved in a normal variable, not in a structure array, I can retrieve the image. However, for my programme I would need to save images in the respective cells of a structure array or something similar. Any idea how to get this done successfully? Thanks J
stiAll{i,y} = imread(fileNameStr); looks like a cellArray. And you try to plot it image(stiAll(i,y)) now as Matrix. Try image(stiAll{i,y})
Convert "polygon((" to GeoJSON
i´m trying to convert a file which i exported from openJUMP to GeoJSON. For example: POLYGON((6.09836816787714 51.96887588500988, 6.098301887512321 51.96438980102539, 6.0997509956359295 51.96348190307623, 6.099466800689811 51.9437370300293, 6.099460124969539 51.94330596923828, 6.099398136138973 51.939044952392635, 6.099389076232853 51.93835067749035, 6.099374771118278 51.93745422363287, 6.099363803863639 51.93655395507824, 6.099881172180176 51.93453598022472) (shorted example). When i convert it per hand, everything is fine and it works. But there are ~ 50 Polygons and maybe its possible to convert them automatically? How is the filetype called?