I am trying to do image processing on an image in Julia. I have a binary mask for a region of interest within my image. I need to find the border of pixels just outside of my mask. In python I can use skimage.segmentation.find_boundaries, and in Matlab I can use boundarymask. Does Julia have any convenient tools to do this?
I found a quick and dirty solution using PyCall which I will post for now, but if anyone finds a better solution that uses standard Julia modules I will accept that answer over mine.
using Conda
using PyCall
Conda.add("scikit-image")
find_boundaries = pyimport("skimage.segmentation").find_boundaries
mask = # load mask ...
border = find_boundaries(mask)
Related
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
Please advise some R packages on rotating or flipping image on R.
Thru package and , i'm able to read pic and turn into matrices (or data frame), however, duto the angle of shooting, the photo is tiled (or not directly facing me). I would like to manipulate the data, so I can adjust the angle.
My plan is to define the normal line of the left pic, and recalculate the angle, but failed. Guess there could be some image manipulation packages for this.
Have tried the CRAN TASKS, yet, most of the packages are for creating images, not to manipulate the outside-in images.
I need to convert rgb image into binary image so that I can use bwlabel() function to detect the no of objects in the image in R. I have just started working on image processing, so I don't have any idea how to do it. I am using EBImage package.
Can anyone help me with this?
Thank you
An example with the lenac image from the package:
lenac = readImage(system.file("images", "lena-color.png", package="EBImage"))
lena = channel(lenac, "gray")
lena5 = lena > 0.5
labels = bwlabel(lena5)
max(labels)
gives 770 objects in the lena picture. Since this is a picture of a face, dividing it into objects may not make much sense. Try different values of the threshold until you get something reasonable - it depends on the type of images you are working with.
I have a code to plot a world map with a meteorological field for one moment (or one measure).
Is it possible to successively plot the map for different moments (for i from 1 to 125) in order to view a sort of video when we run the code?
Yes, look at the animation package.
It can creates an animated gif for you (as well as other tricks). There are live examples you can look at as eg Buffon's needle, a CLT demo and much more.
The package abstracts away some of the OS-dependent layers. If you know the basics, you can of course just call the corresponding tool from the imagemagick project which is likely to be available on OS of choice too.
I would like to know if R allows to pan and zoom images produced with the "plot" function. I would like to obtain the plot transformation using the mouse and not through the command line, is it possible?
Thanks in advance.
It's a bit old question but for future references, I've wrote a package doing precisely that (based on zoomplot {in pkg:TeachingDemos}). It's called zoom:
The CRAN page on zoom
And you are welcome to check the latest and greatest and expand the package on Github
Usage -
library(zoom) # Invoke the Library
# Call plot
zm()
The instructions for Usage in a normal plot is
Mouse:
Scroll to zoom in and out
Hold left mouse button to move
Keyboard:
Left/Right (h/l): move left/right
Up/Down (k/j) : move up/down
+ or i / - or o : zoom in/out
L/H : zoom in/out (x-axis only)
K/J : zoom in/out (y-axis only)
p : print to file
r : reset limits
s : show limits
q on the graphic window to quit
Not with the default plotting device as its internal model is 'static'.
There are workarounds, tough: look for example at package playwith, or at a Java-based device such as the iplots package on Simon's rforge. There are also extensions like ggobi and other on-going work (such as the Qt-based device which will in time replace ggobi) which try to make R-based graphing more dynamic.
But the main takeaway is: not, not really -- due to the way R graphics devices are designed.
To add to Dirk's answer: see also the iWebPlots and RnavGraph packages.
You should look at Greg Snows zoomplot {in pkg:TeachingDemos}. You may be able to call that function with cursor interface using the tk toolkit. I think Greg's package also has examples of such an interface.
To add to existing answers: I like to use the identify() function to manually add labels just to particular points I want.
You can also add R graphs to plot.ly . This should be enough for the most common stuff.
Stefan
Now there are also http://www.htmlwidgets.org/ that add a great set of interactive visualizations capabilities to R. Most of them can easily be zoomed and panned.