Getting Julia to talk to Mac Plotting Devices - macos

Running julia code from the command line, cannot get plots to show.
Simple example:
using ImageView
using Images
img = load("../images/cat.jpg")
imshow(img)
In a notebook
img shows the image, but running the above script from the command line, the code runs without fail, but no plot is ever visible.
Have searched, but have not been able to find documentation on how to get it to talk to, e.g., Quartz (like R does) or other plotting device.
Any help or redirecting to resources would be greatly appreciated.
Thanks!

Related

Images turning green-blackish when passing them to dataloaders

I'm working with fastai, trying to pass some images to a dataloader. The original images are kind of pinkish, but after passing them they appear mostly as green-black (see image in link below):
Original pinkish image (up) and example images (down) after passing them to dataloader, and the code.
The code I've used for the datablock and to show the images is:
example = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=GrandparentSplitter(),
get_y=parent_label,
item_tfms=Resize(128)) #already tried it without item_tfms just in case, still black-green
dls = example.dataloaders(path)
dls.show_batch(nrows=1, ncols=3)
I tried with .tif and .jpeg images, and both show the same problem. The only thing that comes to my mind is that somewhat somewhere is not reading correctly the color format (RGB according to my original files), or maybe transforming it; but I'm not able to figure it out.
Just in case it's important, I'm working in a Jupyter notebook with a MackBook Air M1.
Thanks!
Irene

P3D sketch not working in Python mode of Processing

I was translating a Java sketch to a Python sketch in Processing. It is using the P3D engine and it is not showing anything in the window while it is showing what I want in Java mode. When I run it just shows a blank black window instead of a grid. I can change its background color but I can not draw in the shapes or something window. Please help me! And I can not share its code as it is not an open source project.
It was my fault. It was a mistake in the code. I was making the grid using for loop and the variables that were needed for for loop were not defined properly it was not giving an error because the value of variables was 0. Sorry for wasting your time. Enjoy!

How to set image in axes in matlab GUI?

i have a code which gives several images as ouput and i want to set all these images in particular axes in GUI in matlab. I'm trying to make a GUI of the code.
For eg.
figure,imshow(s1);
figure,imshow(s2);
figure,imshow(s2&s1);
and i want to set the output image of first command in, say axes3, output image of second command in axes4 and similarly last output image in axes5.
Although i know i need to use
set(handles.axes...)
command but i don't know the exact syntax on how to make the image be shown in particular axes.
Please give explain on how to make this happen with any suitable example. Thanks in advance.
One line solution (for each image) is to set the axis as the parent of the image within the imshow command;
imshow(image_Data,'Parent',handles.axes1)
There should be no need to open the additional figure windows ( assuming the axes are with the gui...)
So specifically for the question above:
imshow(s1,'Parent',handles.axes3);
imshow(s2,'Parent',handles.axes4);
imshow(s2&s1,'Parent',handles.axes5);
First you should create an axes box in your gui, then in tag section get a name i.e. (original) and finaly in editor when you want to use it code something like this
A = imread (Path);
axes(handles.original);
imshow(A);
I hope to help you...

OSX: automated (every 1-2sec) screenshot (not full screen but (x,y,w,h)) using python

I want to make screenshots on OSX using python. I dont want make full screen shots but only certain rectangles on the screen. Something like (291,305,213,31). I need the correct pixel because afterwards the image files are processed by OCR (python-tesseract) to extract the text.
By the way this is since 6 years the first time I am programming, so far I only know Java a bit. I started yesterday and gave up this morning at 4am. So basically I have no clue yet...For example I still cannot build with Sublime because of path settings, but thats a different story. Cant figure out everything on one day.
I was trying already the following:
- wxPython
But the result are black images, see also:
stackoverflow.com/questions/8644908/take-screenshot-in-python-cross-platform
Additionally it only works in 32-bit mode, but when I do OCR using python-tesseract openCV requires 64-bit....
autopy
when trying to install I got errors, see also:
stackoverflow.com/questions/12993126/errors-while-installing-python-autopy
ImageGrab
only Windows
effbot.org/imagingbook/imagegrab.htm
commandline screencapture
os.system('screencapture test.png')
When I found this I thought, nice but only fullscreen when checking man screencapture. But then I found this: guides.macrumors.c om/screencapture
-R capture screen rect
That would be already enough, but on OSX 10.7.5 I dont have this option. Any ideas?
import Quartz.CoreGraphics
neverfear.org/blog/view/156/OS_X_Screen_capture_from_Python_PyObjC
Create screenshot as CGImage
image = CG.CGWindowListCreateImage(
region,
CG.kCGWindowListOptionOnScreenOnly,
CG.kCGNullWindowID,
CG.kCGWindowImageDefault)
Unfortunately the image is not in file format but a CGImage, no idea how to save as file.
So if possible I would like to use the commandline screencapture with -R if somebody knows how. Just as a start to continue.
Are there any other command line tools available?
What about other libs that I have missed?
Cheers
M
Given that you can get a CGImageRef, you can get its pixel data using the techniques described in Technical Q&A QA1509: Getting the pixel data from a CGImage object. In particular, it shows a function to get the pixel data as a CFDataRef using this function:
CFDataRef CopyImagePixels(CGImageRef inImage) { return CGDataProviderCopyData(CGImageGetDataProvider(inImage)); }
and says:
The pixel data returned by CGDataProviderCopyData has not been color
matched and is in the format that the image is in, as described by the
various CGImageGet functions …
It shows an alternative for getting the pixel data in other formats if you need that.

MATLAB newbie: error using "saveas" to save a plot as a pdf file

I am a Mac (10.6.8) user. I have written MATLAB code for plotting calculation results and then saving the plots as pdfs. I use "saveas" (see example below).
I get this error:
??? Error using ==> print at 325
Problem converting PostScript. System returned error: -1.Failed to convert to output format; Ghostscript status: -100.**** Unable to open the initial device, quitting.
Error in ==> saveas at 155
print( h, name, ['-d' dev{i}] )
Error in ==> Results_processor at 1219
saveas(gcf,saveFigTo1, 'pdf')
Here is the relevant piece of code:
calculationResultsPath = '/Me/Projects/ThisProject';
calculationResultsDirectory = strcat( calculationResultsPath,'MATLABProcessedResults' );
mkdir( calculationResultsDirectory );
% ...Code for importing results to be plotted from external files (works fine)...
% ...Code for plotting (works fine)... I get the figures I want.
% The problem is:
saveFigTo1 = strcat(resultsDirectory,'/majorsMgO.pdf')
saveas(gcf,saveFigTo1, 'pdf')
hold off
pause
clf;
Some further information... This worked fine last week when I first wrote it! Since then, I think I updated to Mac OS 10.6.8 from 10.6.7, but nothing else has changed in my code or in the version of Matlab I use (R2009a) (unless I have a very bad memory!).
Also, I came across some older suggestions on similar questions to use "print." I tried using:
print(gcf,'filename'). I did get a pdf, but it would not open in any pdf viewing programme. I assume (but don't know for sure) that this could be related to the fact that I use a Mac. I have noticed that there are a few things (especially related to external file manipulation) that don't run on Mac.
If anyone could help, I would be very grateful.
Update:
I found a GhostScript for Mac and installed it as Chris suggested. Unfortunately, that didn't work. I read on a forum that many Mac users are having problems with MATLAB plots at present, possibly related to java. There was an operating system update (to OS X 10.6.8) last week and that is when the problems began. My code worked before then.
I still have not found a solution to this and I don't think the MATLAB people have either, so if anyone has suggestions about how to save plots WITHOUT using saveas, I would love to hear them. The "print" command does not work for me either--it produces PDFs that I can't open.
I think the problem here is GhostScript dying and not so much Matlab. A Google for that GS error turns up many pages such as this. Is this at all applicable? If you use GS outside of Matlab does it work?
As an aside, you might take a look at this FEX submission export_fig. It has treated me well. Worst case you could output to png and convert to PDF later.
One recommendation I can make is to use a different format that OS X understands and simply convert the result to pdf with a system call
See if the following works:
% Load a test image
im = imread('cameraman.tif');
imshow(im); % display the image
saveas(gcf,'test.tif','tif');
% convert to pdf using a syscall to cupsfilter
!cupsfilter test.tif > test.pdf 2> /dev/null
% open the file with your default pdf viewer
!open test.pdf
If the above is not working, yet another approach is to get the bitmap from the figure window and write it using imwrite. Note, this method doesn't benefit from the nice font scaling features of the saveas and print. This approach assumes the im variable above still exists.
imagesc(im); colormap gray;
% Set the border color to white
set(h,'Color',[1 1 1]);
% Get the image in the figure
frame = getframe(gcf);
imout = frame.cdata;
% on OS X, the stretch window image
% appears in the bottom right corner
% of the image. Remove it.
imout = imout(10:end-9,10:end-9,:);
% Write the image out to a lossless tif
imwrite(imout,'test.tif','tif','Compression','none')
You could then convert the tifs to pdf files as above. The quality of the figure will depend on the figure size. In most cases, I wouldn't use this second approach as saveas handles the fonts nicely. Using getframe is meant only as a workaround to the true problem with saveas.

Resources