OpenCV Image Shape Error - : could not broadcast input array from shape (585,828,3) into shape (585,828,4) - cv2

I receive the error in the title when trying to import certain images. All images are .PNG, however, some work while others don't. I understand that this is due to the third parameter in shape. What does the third parameter represent?
I have been looking in the cv2 shape documentation and can not find it.

Related

Have a transparent background in a plot exported from Octave

I am using portable Octave 5.1.0 under Win 10.
I mean to write a plot to png with transparent background.
Disclaimer:
This question is similar to the two linked below.
I opted asking the present different question since I am adding further relevant information (by the same token, question #2 below was not a dupe of #1).
This is what I found:
print(gcf,'-dpngalpha', 'myplot.png');, suggested in Saving a plot in Octave with transparent background, does not work for me.
It is remarkable that I did not find documentation on this option.
This answer has a couple of issues for me: 1) for some unknown reason convert does nothing. 2) The requirement of an external package makes it cumbersome. For instance, I cannot simply send my Octave code to someone else for him to use it.
Option svgconvert is the only official documentation I found.
But it would not apply to a png, e.g.
imwrite seems to have the capability to write with transparency, but I couldn't find a way to transform a plot into and image suitable for imwrite.
(See also Matlab documentation).
Perhaps this is a possible route...
Is there any option available in Octave?
Related:
Saving a plot in Octave with transparent background
Printing / saving a plot as a png file with an alpha channel issue in Octave
http://mlab.no/blog/2014/06/image-transparency-overlay-with-gnu-octave-using-ycbcr/
The imwrite option seems to work. First create the image file img_fname, then create an alpha layer for it.
It would be interesting to know if one could avoid the intermediate non-transparent file.
EDIT:
I managed to create the image directly from my plot, instead of requiring the intermediate file.
x = -10:0.1:10;
plot (x, sin (x));
# Print figure directly to image instead of file
im = print(gcf, '-RGBImage');
tcolor = [255 255 255];
alpha(:,:) = 255 * ( 1 - (im(:,:,1) == tcolor(1)) .* (im(:,:,2) == tcolor(2)) .* (im(:,:,3) == tcolor(3)) );
imwrite(im, 'temp.png', 'Alpha', alpha);
Notes:
With a little simple algebra one could add transparency for any number of colors, and any opacity level for each color.
Moreover, one could move this into a function.
The multiplication of im and tcolor could be possibly vectorized as well.
Related:
https://www.mathworks.com/matlabcentral/answers/57664-how-to-add-alpha-channel-to-the-image-and-convert-that-image-into-png-format

multiple-polygonal for clip area

How do I use the multiple-polygonal of dust's sources in a wide area at google earth engine? (This polygon is separate and unmatched) The program runs but does not output the error occurred:
A region must be a GeoJSON Polygon or LinearRing. Got: 'GeometryCollection'.
I cannot use from box around area, because that area is big
From what i understand of your question you are trying to clip an image using multiple polygons in a same object. If that is the case, then it should not be an issue. You can clip the image with your multiple-polygons as follows
image = image.clip(multigeometry);
However, I assume that you are getting your error during exporting the clipped image. If this is the case then you probably got the error because u used the multi-geometry in "region" argument in the Export function. This is because the export REQUIRES you to have a polygon or linearRing to get the extents of your raster. So you need to use the box in this case. However, the exported image will have the pixels you clipped out as masked pixels.
If you would like to have a different image for different polygons then you could iterate through the polygons to create a clipped raster for each polygon and then export them.

Visio ShapeSheet manage shape data text using connection points of master

I am trying to display shape data on a dynamic connector in Visio. This is to display the connection descriptions between classes in a class diagram.
The problem that I face is that visio does not automatically place the data graphics elements (shows in green in the graphic) in a good location when dealing with 2D connection shapes (the placement options are all relative the the shape centre) -- This does not work well with long connectors.
My intention is to use the two connection points at the end points of the connector (shown as CxnLeft and CxnRight) to place the data graphic shape (Text Callout - ID 22 below) in a position that is relative.
I have tried to create a custom parameter (User.LabelPosition3) on the shape data graphic (green shape) so that I can define its x and y co-ordinate however I have not found a way to access the connection shapes Row_1.X property -- As you can see the formula is not working)
I require assistance in any way to access this value. or a technique that would be better to provide this functionality
The Sheet.5 in your formula is incorrect. According to the image that you posted, the correct reference to your connector shape should be sheet.17.
In the Shape Name box (near the top of the posted image), the ID of the shape is 17. You probably extracted Sheet.5 from Master: Association.Sheet.5 which is incorrect.
Therefore to fix your formula, simply type:
User.LabelPosition3 = Sheet.17!Connections.CxnLeft.X
But I think the full formula should be:
User.LabelPosition3 = Sheet.17!Connections.CxnLeft.X + Sheet.17!BeginX

Corona: display zoomable vector files (like .pdf)

Is it possible to display a zoomable vector file in Corona?
Specifically: I'd like to display a map in an app I am building, and I'd like it to be a vector rather than an image so that the resolution remains the same as the user zooms in or out.
If anyone has an alternate method to get this result I'm interested in that too.
CoronaSDK doesn't have a "vector format loader" built in, but is able to draw lines, polygons, circles and the like - you can get more information here:
http://developer.anscamobile.com/reference/factory-functions
With this in mind, you could create your own custom format (in Lua, probably) saying things like "draw a line from here to here" or "there is a circle with this size on this position".
For zooming in/out, you could just add a "parent" for all your graphical objects, call it "map", and use map.scale - http://developer.anscamobile.com/reference/index/objectscale

where could we get such a landscape GIS layer

Here, I found a landscape GIS layer is really attractive, especially for presenting species/samples distributions. I would like to know if it can be reached in R or any other resources?
The GIS layer were used in Fig 1. in this article (http://onlinelibrary.wiley.com/doi/10.1111/j.1469-8137.2010.03479.x/full).
This Fig 1 image is here:
http://onlinelibrary.wiley.com/store/10.1111/j.1469-8137.2010.03479.x/asset/image_t/NPH_3479_f1_thumb.gif?v=1&t=gsk5sbhs&s=e5e2e4bbb194f799f7ab9bec85a416e295405784
I have ever tried to submit this question in R-sig-geo. But, I failed. I expect to get some helps/directions here.
Thanks a lots for any directions.
Best wishes,
It is very possible to download this file and read it in with R, configure it to have the correct geo-coordinates so that overplotting works easily, and showing the image with the right colour scheme and so on. But, automating getting all of the data you need is not so easy.
You need the colour table from the GIF file so that you can plot the correct set of RGB values for each pixel (the information is in the file, but I'm not sure if this can be obtained directly with R, I will check - it certainly can be with GDAL, but extracting those values in an automated way depends on various tools being available).
UPDATE: It turns out that the raster package gets hold of the colour information correctly and plots it, see below.
You also need the geo-spatial information, i.e. the coordinates of a reference pixel (say, the top left pixel corner), and the scale (the geographic width and height of the pixels) and this information is not stored in the file. Also, the coordinate system of the file is not in the file, and very likely not provided explicitly with the image data.
If the colours and the coordinate system were stored with the file, then it would all be easy and something like the following would be enough.
(Note this worked for me once, but then I think subsequent requests are blocked by the server, so try to only download the file one time).
u <- "http://onlinelibrary.wiley.com/store/10.1111/j.1469-8137.2010.03479.x/asset/image_n/NPH_3479_f1.gif?v=1&t=gskxvi17&s=0f13fa9dae78bd6837aeee594065c6ca112864d2"
imfile <- paste(tempfile(), ".gif", sep = "")
download.file(u, imfile, mode = "wb")
library(raster) ## rgdal also required for this file format
library(rgdal)
im <- raster(imfile)
plot(im)
This looks fine but now see that there is no "real-world" coordinate system, this is just an axis from pixel 1 to the number in the X dimension (and same for Y).
axis(1, pos = 2)
So, still we need manually work to discover appropriate reference coordinates for the image - and guesses here can work fine, but still they are only guesses and you may end up creating a lot of pain for something seemingly simple.
If plot points interactively is enough for you, then you might use locator in conjunction with points and lines and text, and related plotting functions.
Feng,
if I read the Google docs correctly, you can modify the labels and displayed features with the extra parameters style and element.
I did not include custom parameters for these in the RgoogleMaps package, however, you can easily pass ANY addition parameters via the path argument !
If you read the help file for GetMap carefully, you will note the following example:
note that since the path string is just appended to the URL you can "abuse" the path argument to pass anything to the query, e.g. the style parameter:
#The following example displays a map of Brooklyn where local roads have been changed to bright green and the residential areas have been changed to black:
## Not run: GetMap(center='Brooklyn', zoom=12, maptype = "roadmap", path = "&style=feature:road.local|element:geometry|hue:0x00ff00|saturation:100&style=feature:landscape|element:geometry|lightness:-100", sensor='false', destfile = "MyTile4.png", RETURNIMAGE = FALSE);
Hope this helps,
Markus Loecher
If you just want data like this image, then there are packages to access imagery directly, again utilizing the tools in sp and rgdal. This example is close using gmap in the dismo package.
library(dismo)
e <- extent(-7, 5, 38, 44)
gm <- gmap(e, type = "terrain")
plot(gm)
Note that while we specify the extents in "longlat" the image comes back in its native (Google) Mercator.
print(gm)
See ?gmap for more options on transforming your own data to match the image's projection, or the broader function set in raster, rgdal and sp for other options. There are other imagery providers that might be preferable, and quite a few options in the R suite of contributed packages.

Resources