how to create a nature shape in matlab? - matlab

i am a newbie here.. please excuse me for asking a straight forward question as i did not have the right information to do so.
for my question above, can anyone help me to create various shape in matlab?
i know how to make a simple triangle, rectangle in matlab.
what i am looking for is how to create animal patterns in matlab. all i need is the boundary layer (outer layer).
like from a bird / butterfly. something like the picture below.
butterfly wing:
can anyone give me tips / links to help me.
and yes, i also did not have the coding. i am totally lost on how to make the pattern in matlab.
my real purpose was to add mesh pattern into the wings. i have the code for the mesh. all i need is the code on how to make the wing shape.

If you already have the image created by another program, you can import it to matlab using imread. If you then want to get a binary boundary, you can use im2bw.
threshold = 0.7; % you can play with this to get what you want
binary_img = im2bw(imread('PATH\TO\IMAGE.jpg'), threshold);
In matlab versions starting at 2016a there is another function called imbinarize you might want to have a look at.
As for creating patterns from scratch, as already mentioned in the comments, matlab should not be your choice. Unless, of course, you have a well defined mathematical equation or a problem solution to which becomes the boundary. For this you can look into fimplicit, fplot etc..

Related

Matlab: Find pattern in an image given a skeletonized template

I am stuck at a current project:
I have an input picture showing the ground with some shapes on it. I have to find a specific shape with a given template.
I have to use distance transformation into skeletonization. My question now is: How can I compare two skeletons? As far as I noticed and have been told, the most methods from the Image Processing Toolbox to match templates don't work, since they are not scale-invariant and rotation invariant.
Also some skeletons are really showing the shapes, others are just one or two short lines, with which I couldn't identify the shapes, if I didn't know what they should be.
I've used edge detection, and region growing on the input so there are only interessting shapes left.
On the template I used distance transformation and skeletonization.
Really looking forward to some tips.
Greetings :)
You could look into convolutions?
Basically move your template over your image and see if there is a match, and where.
The max value of your array [x,y] is the location of your object in the image.
Matlab has a built-in 2D convolution function for this

Over-segmentation of Watershed algorithm

I followed the 2-D Watershed example in Mathworks.com to separate the connected objects, like the image below:
The code is summarize as:
bw = imread('some_binary_image.tif');
D = -bwdist(~bw);
D(~bw) = -Inf;
L = watershed(D);
The result is:
The particle in the center has been separated into two. Are there any ways to avoid the over-segmentation here?
Thanks, lennon310, chessboard does work well for most of my images, but there are still some cases that it doesn't. For example, the following binary image:
Using chessboard will result in:
As I have hundreds of images, it seems that it is difficult to find one combination of parameters that work for all images. I am wondering if I need to combine the good results got from using chessboard, cityblock, etc...
Use max(abs(x1-x2),abs(y1-y2)) as the distance metric (chessboard), and use eight-connected neighborhood in watershed function:
bw=im2bw(I);
D = -bwdist(~bw,'chessboard');
imagesc(D)
D(~bw) = -Inf;
L = watershed(D,8);
figure,imagesc(L)
Result:
I have been dealing with the same issue for a while. For me, the solution was to use a marker based watershed method instead. Looks for examples on watershed method given on the Matlab Blog by Steve: http://blogs.mathworks.com/steve/
This method given by him worked best for me: http://blogs.mathworks.com/steve/2013/11/19/watershed-transform-question-from-tech-support/
Now, in an ideal world, we would be able to segment everything properly using a single method. But watershed does over or under-segment some particle, no matter which method you use (unless you manually give the markers). So, currently I am using a semi-automatic segmentation method; i.e., use watershed to segment the image as best as possible, and then take that image into MSPaint and edit it manually to correct whatever under/over-segmentation remains.
Region growing seems to have been used by some people in the past. But my image processing knowledge is limited so I can't help you out with that. It would be great if anyone could post something about how to use region-growing to segment such an image.
Hope this helps.

Matlab face alignment code

I am attempting to do some face recognition and hallucination experiments and in order to get the best results, I first need to ensure all the facial images are aligned. I am using several thousand images for experimenting.
I have been scouring the Internet for past few days and have found many different programs which claim to do so, however due to Matlabs poor backwards compatibility, many of the programs no longer work. I have tried several different programs which don't run as they are calling onto Matlab functions which have since been removed.
The closest I found was using the SIFT algorithm, code found here
http://people.csail.mit.edu/celiu/ECCV2008/
Which does help align the images, but unfortunately it also downsamples the image, so the result ends up quite blurry looking which would have a negative effect on any experiments I ran.
Does anyone have any Matlab code samples or be able to point me in the right direction to code that actually aligns faces in a database.
Any help would be much appreciated.
You can find this recent work on Face Detection, Pose Estimation and Landmark Localization in the Wild. It has a working Matlab implementation and it is quite a good method.
Once you identify keypoints on all your faces you can morph them into a single reference and work from there.
The easiest way it with PCA and the eigen vector. To found X and Y most representative data. So you'll get the direction of the face.
You can found explication in this document : PCA Aligment
Do you need to detect the faces first, or are they already cropped? If you need to detect the faces, you can use vision.CascadeObjectDetector object in the Computer Vision System Toolbox.
To align the faces you can try the imregister function in the Image Processing Toolbox. Alternatively, you can use a feature-based approach. The Computer Vision System Toolbox includes a number of interest point detectors, feature descriptors, and a matchFeatures function to match the descriptors between a pair of images. You can then use the estimateGeometricTransform function to estimate an affine or even a projective transformation between two images. See this example for details.

obstacle avoidance implementation in matlab

This could be a really broad question, but if you can help me with ideas, it would be a great help to me.
I am trying to implement basic path finding algorithm in matlab. I have to create a map where the robot can navigate and also avoid obstacles and reach destination. I have the algorithm fine with me. But am struggling with the gui as I haven't used much of Gui in matlab.
This is the following idea I had.
I created a plot and just defined 4 coods for each obstacle, destination as a circle and a start point. But am stuck when I think how I can detect whether the robot has hit an obstacle or not. One way is to create the equation of line and try to see if the point ever comes to lie on it. But the movement is based ona random generated variable. Thus it is possible for the robot to cross the line and get inside the polygon.
My apologies for bein too elaborate, but can you please tell me the best way to implement this in matlab? It is mandatory to do this in matlab. Please suggest me a better and easy way to program it. Thanks in advance.
If your obstacles are all polygons you could try to use the ray casting algorithm described on the following wikipedia site.
Point in polygon algorithm
With this you should be able to determine if the robot position lies within an obstacle, or you could determine if the next movement will bring the robot into contact with the obstacle.
If you are looking for a simple algorithm that can take care of obstacles inherently i would suggest the potential fields algorithm (can get stuck in certain cases)
Potential Fields
else you can also try the A* algorithm, which is better in my opinion; Good description of A*

slicing a 3D image data set at different angles [duplicate]

This question already has answers here:
Extract arbitrarily rotated plane of data from 3D array as 2D array
(2 answers)
Closed 8 years ago.
I am working with a 3d stack of CT data. I'm interested to define a plane and slice this 3D image dataset with this plane. I'm using MATLAB to do this. I have attempted a few different approaches, including rotating the image data set prior to slicing it, however, imrotate() only rotates the image in one direction (about the z-axis I believe).
I have also tried defining the plane and intersecting it with each image slice and defining the data points by interpolation. I thought and still think this is a clean way of approaching the problem, however I have not succeeded in finding out why the approach is not working. I understand that my image is defined as coordinates, while when I try to define the plane MATLAB does this through dimensions. As straightforward as it sounds I have been struggling with figuring out the solution for a while now.
I appreciate any help guiding me to a solution.
Thank you in advance!
I would strongly recommend using ITK (http://www.itk.org/Doxygen41/html/annotated.html) for working on medical images. MATLAB is not very helpful when working with large medical images. There are varuous filters in ITK which cna solve your purpose, e.g., ExtractSliceImageFIlter... May be a simple cropping is what you want... Its bit of a pain to learn ITK initially but totally worth it... refer the ITK Documentation and examples... all the doubts that you have about using any function etc can be understood by looking at solved examples give...
http://www.mathworks.com/products/demos/image/3d_mri/tform3.html
i hope this help,
i would also go with magarwal suggestion , matlab people are usually taking ITK filters and implementing it in Matlab,
so if you have C++, java, python , c# or any skill of the above you can use itk .
and Trust me you will be ahead than Matlab while waiting for them to implement filters they already have in ITK