Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that there is <em>misunderstanding</em> in what you are going to do with image files. The following shows the two possible cases based on you question.</p> <p>To read a <code>JPG</code> file into <code>TXT</code> file <strong>without</strong> analyzing image data i.e., no decompressing etc. Use this (what would be the use for this, we are not sure!, BTW). </p> <pre><code>import os from scipy.misc import imread import numpy as np imagePath = 'c:/your jpgs/' savepath = imagePath #save as text no decompressing for filename in os.listdir(imagePath): if filename!='.DS_Store' and filename[-3:]=='jpg': with open(filename,'rb') as fin: b = fin.read() fin.close() out = ','.join(b)+'\n' with open(savepath+'trainMatrix1.txt','a') as fut: fut.write(out) fut.close() </code></pre> <p>output is as: </p> <pre><code>ÿ,Ø,ÿ,à, ,,J,F,I,F, ,,,, ,d, ,d, , ,ÿ,á, </code></pre> <p>To read a <code>JPG</code> file into <code>TXT</code> file <strong>with</strong> analyzing image data i.e., <strong>decompressing</strong> etc. Use this which utilises <code>imread</code> to decompress image data. You will need remember <code>JPG</code> is a heavily compressed image format, so after decompressing, it will be huge text file. You are appending all, so the output will be huge! </p> <pre><code>#save as text decompressed image into bytes for filename in os.listdir(imagePath): if filename!='.DS_Store' and filename[-3:]=='jpg': b = imread(filename,flatten=0).flatten() print b.shape out = ','.join('%d'%i for i in b)+'\n' print len(out) with open(savepath+'trainMatrix2.txt','a') as fut: fut.write(out) fut.close() </code></pre> <p>output is as (color data):</p> <pre><code>255,255,255,245,245,245,125,125,125,72,72,72,17,17,17,2,2,2,15 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload