When I do general PIL commands in Python, I get such an error message:
>>> im.save('layer_86_.tiff')
TIFFSetField: layer_86_.tiff: Unknown tag 33922.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1685, in save
save_handler(self, fp, filename)
File "C:\Python34\lib\site-packages\PIL\TiffImagePlugin.py", line 1185, in _save
e = Image._getencoder(im.mode, 'libtiff', a, im.encoderconfig)
File "C:\Python34\lib\site-packages\PIL\Image.py", line 430, in _getencoder
return encoder(mode, *args + extra)
RuntimeError: Error setting from dictionary
I've seen at Github and SO similar questions, that date back to many years ago. But in my case this problem still can be reproduced. I've even installed libtiff.dll and put it in the System32 and SysWOW64 folders, but to no avail. So, how can I fix it?
This is another error message, that I see, when I try to rotate an image:
>>> from PIL import Image
>>> Image.MAX_IMAGE_PIXELS = 100000000000
>>> img = Image.open('layer_71_.tiff')
>>> img.rotate(80,expand=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1603, in rotate
return self.transform((w, h), AFFINE, matrix, resample)
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1862, in transform
im.__transformer((0, 0)+size, self, method, data, resample, fill)
File "C:\Python34\lib\site-packages\PIL\Image.py", line 1910, in __transformer
image.load()
File "C:\Python34\lib\site-packages\PIL\ImageFile.py", line 245, in load
if not self.map and (not LOAD_TRUNCATED_IMAGES or t == 0) and e < 0:
TypeError: unorderable types: tuple() < int()
So it seems like PIL does not work in many cases.
Related
So I was working on a project and I came across this error related to sympy:
Traceback (most recent call last):
File "c:\Users\Andres\OneDrive - Centre d'Estudis Monlau\z.ottro\final program try 1\testing area 2.py", line 4, in <module>
Ymin = minimum(root(x,3), x, domain=Interval(-7,7))
File "C:\Users\Andres\AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\calculus\util.py", line 837, in minimum
return function_range(f, symbol, domain).inf
File "C:\Users\Andres\AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\calculus\util.py", line 220, in function_range range_int += Interval(vals.inf, vals.sup, left_open, right_open)
File "C:\Users\Andres\AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\sets\sets.py", line 274, in inf
return self._inf
File "C:\Users\Andres\AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\sets\sets.py", line 1910, in _inf
return Min(*self)
File "C:\Users\Andres\AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\functions\elementary\miscellaneous.py", line 391, in __new__
args = frozenset(cls._new_args_filter(args))
File "C:\Users\Andres\AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\functions\elementary\miscellaneous.py", line 564, in _new_args_filter
raise ValueError("The argument '%s' is not comparable." % arg)
ValueError: The argument '(-7)**(1/3)' is not comparable.
I was able to isolate where happened and recreate the error with these lines:
from sympy import *
x = Symbol("x")
Ymin = minimum(root(x,3), x, domain=Interval(-7,7))
I'm not undrestanding why it's happening, as when is root(x,2) it doasn't have this problem. Does anyone have a clue?
Okey i found an answer online posted by user6655984(stackoverflow) and i wanted to share it online:
expression = root(Abs(x), 3)*sign(x)
I am implementing the HOG(Histogram of Oriented Gradient) with below code.
import io
from skimage.io import imread, imshow
from skimage.feature import hog
from skimage import exposure
from skimage import io
import matplotlib
img = imread('cr7.jpeg')
io.imshow(img)
MC = True #Fpr color images
#MC = false #for grayscale images
hogfv, hog_image = hog(img, orientations=9,
pixels_per_cell=(32,32),
cells_per_block=(4,4),
visualize = True ,
channel_axis=MC)
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0,5))
imshow(hog_image_rescaled)
I don't know why i am getting error of dimension.
Traceback (most recent call last):
File "main.py", line 22, in <module>
channel_axis=MC)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 427, in fixed_func
out = func(*new_args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 348, in fixed_func
return func(*args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/feature/_hog.py", line 286, in hog
dtype=float_dtype
ValueError: negative dimensions are not allowed
(base) (env) c100-110#C100-110s-iMac-2 HOG % python main.py
Traceback (most recent call last):
File "main.py", line 18, in <module>
channel_axis=MC)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 427, in fixed_func
out = func(*new_args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/_shared/utils.py", line 348, in fixed_func
return func(*args, **kwargs)
File "/Volumes/DATA/Djangoproject/HOG/env/lib/python3.7/site-packages/skimage/feature/_hog.py", line 286, in hog
dtype=float_dtype
ValueError: negative dimensions are not allowed
Can anyone help me in finding solution to this error.
The error log says there is a problem in "line 22"
Traceback (most recent call last):
File "main.py", line 22, in <module>
channel_axis=MC)
...
ValueError: negative dimensions are not allowed
channel_axis, it's the "channel axis"! So I guess it expects an integer, rather than a bool value.
It is confirmed in the source code:
channel_axis : int or None, optional
If None, the image is assumed to be a grayscale (single channel) image.
Otherwise, this parameter indicates which axis of the array corresponds
to channels.
I think you were trying to use multichannel, which is deprecated:
multichannel : boolean, optional
If True, the last image dimension is considered as a color channel,
otherwise as spatial. This argument is deprecated: specify channel_axis instead.
By adding following, it is working for my case.
channel_axis=-1
I keep getting
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 1076, in _escape_attrib
if "&" in text:
TypeError: argument of type 'int' is not iterable
when I'm trying to write an XML file with some attributes I need to edit.
Here's my code:
import xml.etree.ElementTree as ET
tree = ET.parse('TM_GeneralSettings.xml')
root = tree.getroot()
for item in root.iter('Control'):
numX = int(((720/1080)*float(item.attrib.get('LocationX'))))
numY = int(((720 / 1080) * float(item.attrib.get('LocationY'))))
numW = int(((720 / 1080) * float(item.attrib.get('SizeW'))))
numH = int(((720 / 1080) * float(item.attrib.get('SizeH'))))
print(numX, ':', numY, ':', numW, ':', numH)
item.set('LocationX', numX)
item.set('LocationY', numY)
item.set('LocationW', numW)
item.set('LocationH', numH)
tree.write('TM_GeneralSettings2.xml')
I also get this errors when I run my code:
Traceback (most recent call last):
File "/Users/alessandrochiodo/PycharmProjects/pythonProject/main.py", line 17, in <module>
tree.write('TM_GeneralSettings2.xml')
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 772, in write
serialize(write, self._root, qnames, namespaces,
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 937, in _serialize_xml
_serialize_xml(write, e, qnames, None,
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 930, in _serialize_xml
v = _escape_attrib(v)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 1099, in _escape_attrib
_raise_serialization_error(text)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 1053, in _raise_serialization_error
raise TypeError(
TypeError: cannot serialize 0 (type int)
Can someone help me? I can't find a solution.
I'm using python image_match library. I need to use search_image method of this library. but when I se this method I got the below error:
Traceback (most recent call last):
File "/var/www/html/Panel/test2.py", line 16, in <module>
ses.search_image('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg')
File "/usr/local/lib/python3.10/site-packages/image_match/signature_database_base.py", line 268, in search_image
transformed_record = make_record(img, self.gis, self.k, self.N)
File "/usr/local/lib/python3.10/site-packages/image_match/signature_database_base.py", line 356, in make_record
signature = gis.generate_signature(path)
File "/usr/local/lib/python3.10/site-packages/image_match/goldberg.py", line 161, in generate_signature
im_array = self.preprocess_image(path_or_image, handle_mpo=self.handle_mpo, bytestream=bytestream)
File "/usr/local/lib/python3.10/site-packages/image_match/goldberg.py", line 257, in preprocess_image
return rgb2gray(image_or_path)
File "/usr/local/lib/python3.10/site-packages/skimage/_shared/utils.py", line 394, in fixed_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/skimage/color/colorconv.py", line 875, in rgb2gray
rgb = _prepare_colorarray(rgb)
File "/usr/local/lib/python3.10/site-packages/skimage/color/colorconv.py", line 140, in _prepare_colorarray
raise ValueError(msg)
ValueError: the input array must have size 3 along `channel_axis`, got (1024, 687)
Can you please help me?
I have defined a new derived dimension with
[molar_energy] = [energy] / [substance]
However, if I do the following it complains:
>>> UR.get_compatible_units('[molar_energy]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 881, in get_compatible_units
equiv = self._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 2082, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 1835, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 891, in _get_compatible_units
return self._cache.dimensional_equivalents[src_dim]
KeyError: <UnitsContainer({'[length]': 2, '[mass]': 1, '[substance]': -1, '[time]': -2})
I saw that there is a conversion included in a context but I don't use it. What I am doing wrong?
Thanks for your help
PS: logged issue https://github.com/hgrecco/pint/issues/1418
Just leaving the solution here for anyone who faces this issue as well.
I just added a made-up unit and it worked
# Molar Energy
[molar_energy] = [energy] / [substance]
mol_en = J / mol