Gradient options via Wand - wand

I have installed the most recent versions of ImageMagick (7.0.8-27 Q16 x64 2019-02-09) and Wand (0.5.1) on a Windows 7 computer.
I would like to know if the gradient options can be used in Wand—the options that are listed on https://imagemagick.org/script/gradient.php, that can be set using the -define argument in command line.
I know that the following Wand code generates a gradient.
wand.image.Image(width=100, height=100, pseudo='gradient:white-black')
Is it possible to use the gradient options via Wand? If so, how?

Yes! Although it's a little awkward in python. You need to set the property before reading the image. Usually like:
Allocate an instance of wand w/o an image
Set the definition on Image.options dict.
Read pseudo format
For example...
from wand.image import Image
with Image() as img:
img.options['gradient:vector'] = '10,10,75,75'
img.pseudo(256, 256, 'gradient:white-black')
img.save(filename='output.png')

Related

How to write pre processed image

#Read the image
img = cv2.imread('../input/jagan-ap/AP CM Jagan Mohan Reddy approves....jpg')
#Pre processed the image. (Done pre-processing)
#Then I want to write this image into output directory of the Kaggle, tried below options but no use:
1 img.fromarray(roi_color).save('./output/')
2 cv2.imwrite('./output/',img)
3 plt.imsave(img, 'saveName.jpg')
Kindly suggest any other solution.
As you used OpenCV to open the image and you already have that as a dependency, there's little reason to suddenly introduce PIL or matplotlib as further deoendencies as in 1) and 3). Furthermore, your colours will be wrong because OpenCV uses BGR ordering and the others use RGB.
So, let's look at 2). If output is a directory, that can't work. You need to write to a file, so try:
cv2.imwrite('output/result.png',img)

How to get opencv image in an enaml space - Is it possible?

Is it possible to have enaml as target for OpenCV?
I'm thinking how to setup GUI and what to use.
Nothing too complicated, I need to be able to set some bitmap background, draw rectangles and circles over it, but also have the possibility to select/move these graphics objects.
Also, I would like that I do not have to take care of all these elements when I stretch the window, etc. they should do this automatically since they would be defined in some "absolute" space. I think I could easily make it work for the bitmaps (even from memory), by overriding request_image in ImageProvider object (even though I see some strange cache happening in provider/enaml view).
Problem that I'm having now with OpenCV (OSX 64) is that even when I get resize to work with qt backend and CV_WINDOW_NORMAL, the content does not stretch.
I like OpenCV, because easily I get basic UI functions.
On the other hand I started to like enaml so I'm thinking did anyone manage to get these to to work together.
I'm thinking if link with MPL works, it's possible that coupling with OpenCV should be possible :)
Thanks!
If you can get your image into argb32 or png format, you can use an Enaml ImageView to display it.
Take a look at the ImageView example:
https://github.com/nucleic/enaml/blob/master/examples/widgets/image_view.enaml
This should do it:
from enaml.image import Image
from cv2 import imread, imencode
open_cv_image = imread('./cat.png')
png_image = imencode('.png', open_cv_image)[1].tostring()
enaml_image = Image(data=png_image)

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 Plot to image without display and save on a no Java server

For the normal answers to this question, it is provided here: In MATLAB, how do I plot to an image and save the result without displaying it?
However, this will not work on a server that does not have Java support. This is the output:
>> testScript
??? Error using ==> imshow at 191
IMSHOW requires Java to run.
We cannot install Java in this server.
Of course, one of the answers suggest to modify the image directly, then go for imwrite. However, it is too primitive, and at this level, we should already have some sort of function that can draw lines. What are some of the other available options for drawing directly on the image matrices?

Properly converting a CMYK image to RGB with RMagick

I have been using the below to do a color conversion
if #image.colorspace == Magick::CMYKColorspace
# #image.colorspace #=> CMYKColorspace=12
#image.colorspace = Magick::RGBColorspace
#image = #image.negate
end
It works, approximately, but the color luminosity is off. The fact that I need to negate the image leaves a very bad smell.
The documentation mentions using color_profiles, but beyond that I can not find much.
I am now trying
#image = #image.quantize(16777216, Magick::RGBColorspace)
And the colors are better, but still off.
Thanks Pekka, you tipped me off to the answer (+1).
You must have ImageMagick compiled with the Little Color Management System (LCMS) installed. This may already be the case if an installer or package was used. But I was compiling from source. It was as simple as installing LCMS from source and rebuilding ImageMagick (./configure; make; make install).
In ImageMagick the below works well to reproduce accurate color:
convert FILENAME -profile /PATH_TO_PROFILE/sRGB.icm OUT.jpg
So in RMagick I use the below:
if #image.colorspace == Magick::CMYKColorspace
# Adjust the path as necessary
#image.color_profile ="/usr/local/share/ImageMagick-6.5.4/config/sRGB.icm"
end
#image.write("out.jpg") { self.quality = 85 }
I've spent a long time trying to go from a CMYK EPS to a RGB PNG using RMagick and Rails. Hopefully this will be of use to someone:
def convert_image_from_cmyk_to_rgb( image )
#puts image.alpha?
if image.colorspace == Magick::CMYKColorspace
image.strip!
image.add_profile("#{Rails.root}/lib/USWebCoatedSWOP.icc")
image.colorspace == Magick::SRGBColorspace
image.add_profile("#{Rails.root}/lib/sRGB.icc")
end
image
end
You can download the ICC files direct from Adobe at http://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html
The only thing I haven't been able to suss is how to maintain transparency. The EPS I want to use has a transparent background which is being turned into white. Unfortunately I can't do something like image.transparent( "white" ) as I have white in the image that I want to keep as white.
If I uncomment the puts image.alpha? in the above code it returns false.
Does anyone know if what I'm trying to do is possible with the current version of RMagick, as I'm beginning to wonder if importing CMYK EPSs with transparency isn't supported.
Thanks!
The incoming files, in this case, do
have a profile. I will investigate
some more. I got lost with the color
profiles (like where do I download
them? the ICC site was not much help)
You are not the only one confused; I was too. There are discussions on the ImageMagick site that might be worth siftirng through: Here As far as I understood back then, properly working with profiles is possible when the profile used can be identified (e.g. a monitor profile) or is embedded in the file (which can be done at least for TIFF and JPG in Photoshop, I think). Check e.g. this: Here. Good luck.
I found that The Who's command line solution worked beautifully, but the RMagick solution did not work for me.
To get it to work in RMagick, I instead I had to use the Magick::Image#add_format method, which, according to the docs, will allow you to specify an source and destination profile. It looks like this:
if img.colorspace == Magick::CMYKColorspace
img.add_profile(RGB_COLOR_PROFILE)
end
RE: LCMS on Centos 5.5, be sure to download and build the latest LCMS from source (vs. yum install). Otherwise, IM won't find LCMS at build and you'll be scratching your head, like me, wondering why LCMS isn't included in IM delegate libs.

Resources