how do I open an image using the python image library? - python-imaging-library

I am using the image library with python for the first time and am trying to open an image on my pc. So I type in
Image.open(C:\Users\laurence\Google Drive\INB347 web 2.0)
and I keep getting this:
SyntaxError: invalid syntax: with the colon just after the C highlighted in red.
It does not mention this in the handbook which I am following. The example uses
a simpler file location: ('bride.jpg'). How do I open an image file please? thanks.

Try this:
Image.open(r'C:\Users\laurence\Google Drive\INB347 web 2.0')
i.e., enclose your full path in quotes, and put r in front of it to denote is as a 'raw' string, meaning Python won't try to interpret it as anything other than what you put between quotes. You can read more about raw strings here.

Related

How do I use an SF Symbol in Swift using its symbol literal instead of its name?

The normal way to use an SF Symbol is to find the image you want in the SF Symbols app, copy its name, and then use this name in the Image(systemName:) constructor. For example, if I'd like to display the share Icon, I could use the following code:
Image(systemName: "square.and.arrow.up")
This will produce the following image in the UI:
This is great, but just like color and image literals, I was hoping that instead of the string square.and.arrow.up I could have something more literal in my code. For example, if I choose "Copy symbol" in SF Symbols and then paste that into Xcode, I get a string which represents a "symbol literal":
If I try using that code, though, I get the following error:
No symbol named '􀈂' found in system symbol set
Is there another way to use this Symbol within Xcode and have it provide me an Image with the corresponding systemName so I can stop using the string square.and.arrow.up in my codebase and instead use the symbol literal?
My current workaround is to add the literal symbol as a comment, but I'd like to avoid duplicating the symbol:
Other things I've tried:
Image(_ name:bundle:): This doesn't show anything.
Text(_ content:): This shows a black square with a question mark.
Using an #imageLiteral: I investigated this a while ago but couldn't find a way to do this.
Image literals don't work in Xcode these days, and haven't worked for a long time. You have to refer to the string "square.and.arrow.up" in order to specify this image; there is no other way. You can give the string a synonym; you can use the storyboard to fetch the image into an image view so that you don't have to do it in code; but there is no other "magic" way such as you are envisioning.

How to save a .mat file using a name with a :

If I do x='bob:.mat' and then try to save it as a mat file like so:
number=10;
save(bob,'number');
I get an issue where it can't be saved, and I am assuming this is the case because: is a special character. I looked up online how to use it, and an example told me to put a ' mark before it, but that didn't work. Any help would be appreciated.
It should be: save('bob.mat', 'number');
Or
save bob number
save('bob', 'number'); also works.
save('bob:', 'number'); results an error (in Windows):
Error using save
Unable to open file "bob:" for output.
A file name with : is not allowed, because it's reserved for drive letters like C:.
A workaround is described here: How to get a file in Windows with a colon in the filename?
Following code actually does work:
save('bob꞉','number');

Calling shell from swift app with arguments

I am using the solution described in here to call a command line tool from within my Swift app, but always receive an error for the file I am giving as an argument.
If I just copy the complete call string to Terminal, it runs just fine.
My first thought was that it might has to do with the spaces in the file path, but that does not matter. Since the response comes from the tool itself, not from shell, the call seems to be OK in general. The path that I am using as an argument comes from a file dragged into the app from the finder.
Call from Swift:
self.shell("/Applications/AtomicParsley","'\(FileURLLabel.stringValue)'","--artwork REMOVE_ALL --overWrite")
Response in console:
AP error trying to fopen '/Users/Tom/Downloads/Test file.m4v': No such file or directory
AtomicParsley error: can't open '/Users/Tom/Downloads/Test file.m4v' for reading: No such file or directory
Thanks, pbodsk, using path of NSURL was the solution. Besides, I had to use string constants rather than just the literals for the other parameters as well when calling the shell. Thanks alot!

Display contents of text file in MATLAB shell

I'm using MATLAB under Windows, and trying to display (dump) the contents of a text file in the command shell. It seems like overkill to open a small file in the editor, or to load the file to use disp.
Use type and specify the explicit file name (including the extension), for instance:
type('myfile.txt')
As well as type, there's also dbtype which lets you pick a start and end range to print, and shows line numbers - handy for listing source files.

Error in calling ImageMagick from Matlab

I have installed ImageMagick in my system (windows), and its commands are there in system PATH. Its working absolutely fine through Command line
I want to call the "convert" function of ImageMagick from Matlab using system command.
'C:\Users\Vivek' is the Path to image. I have to test working of ImageMagick through Matlab, as i need it in further processing (Making input suitable to Tesseract OCR)
cmd= ['convert ' 'C:\Users\Vivek\208.jpg ' 'C:\Users\Vivek\208.png']
system(cmd);
It says Invalid Parameter - C:\Users\Vivek\208.png, I tried some other ways. But, all the time the problem is with the second parameters.
Need Help
Thanks
Windows comes with its own convert program, and it looks like you're calling that one because it's first on the path in this context. It's described here on ImageMagick's site: http://www.imagemagick.org/Usage/windows/#convert_issue
I do not have ImageMagick installed, and I get the same error message when I try calling convert. That's consistent with your code getting the wrong convert program.
C:\Users\janke>convert C:\Users\Vivek\286.jpg C:\Users\Vivek\208.png
Invalid Parameter - C:\Users\Vivek\208.png
Specify the full path to ImageMagick's convert program and it should work for you.
The solution mentioned in the last post is the standard way to solve the issue, but the simplest way to do this is to just rename the ImageMagick's convert.exe file to something else, like convert1.exe, and use this filename in your scripts.