Posts

Posts mit dem Label "Matlab" werden angezeigt.

Matlab: Point on ellipsoidal surface

Bild
( German ) This post is focussing on the solution of calculating a point of an ellipsoidal surface in dependency of to angles like in spherical coordinates. Mode of operation: This function calculates the closest point on an ellipsoidal surface from an point outside or inside the body in respect to its center. It needs the mesh data of the ellipsoidal body X, Y, Z and the point, where the point with direct connection to the center should be found on the surface. The output parameters are [point, phi, the] = PointOnSurfaceAnalytic(X, Y, Z, x, y, z); the surface point and the angles phi and theta of the ellipsoidal equations. It can be downloaded here .   To derive the formula we start with the ellipsoidal equation: (x/ a)^2 + (y/ b)^2 + (z/ c)^2 = 1   If we consider 𝝋 to be between the x and y axis and  𝝑 be between the y and z axis it leads to: x = y/tan 𝝋   z = y/tan 𝝑   Substitute this in the ellipsoidal equation one gets: (y/...

Matlab: Classification

Bild
( German ) This post describes a Matlab function which classifies images dependent on shape color and so on to differentiate between images like bananas and apples. Mode of operation: In this function different attributes of images are calculated in values to classify images and seperate them in 2D or 3D. Classification methodes are 'color', 'color2' and 'colorhex' for different color classifications and 'brightness' for the brightness value 'shape', 'std', 'mean', 'cov' and 'sub' are different shape conditions. This function can be downloaded on MathWorks . Following figure shows the classification of apples, bananas and black berries.  It is seen in three dimensions it is clearly classified. Most of the mathematical algortihm are based on magnitude gradient maps to whether calculate shape or substructures. Following figure shows the different input images and their gradient map. In source code giv...

Matlab: Convolutional Network for Dice identification

Bild
( German ) This post describes a Matlab function which uses a 7 layer convolutional network for dice number identification (numbers 1-12). It calls for the earlier proposed image processing methode shown in this post . Mode of operation: Two methodes were tested. The dice as shown in previous post is just a tiny part of the whole image. With image processing, the dice itself is excluded and saved in a new folder sorted by number. They are loaded in "digitData". The it is splitted in trainigs set (4/5) and test set (1/5 of alle images). All in all I have 996 images and I tested the not processed images and the binare tresholded images, which suprisingly showed a higher accuracy for the non processed images. An all in all accuracy of 99.6% in the training set and 99.2% in the test set was achieved around 5% higher than for the binare images. In this image the value of accuracy is seen what the convolutional net predicts. A good improvement is seen in non processed images c...

Matlab: Sorting Songs/Files

( German ) This post describes a Matlab function which load out of a folder all songs, process them to a standarized name and save them in a folder in the different interpret folders. Mode of operation: First of all the path is chosen where the songs are, which should be sorted and then the folder is chosen, where the songs are copied to. Because in many folders are files like "..", ".", "desktop.ini", these are filtered. So now are all names of the file loaded. Next the name (interpret and songname) is devided and also further informations in the name like "(Official Video)" or "[pleer.net]" are cutted out.  Now the first song is taken and if there is a folder existing in the folder where it should be saved, then the song is saved, if it isn't already in the folder. If the interpret folder is not existing right now a new folder is generated with the name of the interpret and the song is copied into it. This is done for al...

Matlab: Image background removing and cutting

Bild
( German ) This post is about a Matlab function where one can load an images and remove the background, by saving it as a transparent image. The background can consist out of different and blurring colors! Useful for prensentations that the image fits to the slice background. Mode of operation: This is a GUI based function, so that one can load via interface an images of any type. Now one can use the buttom "Choose BG" to select the background color in an additional appearing image. If it is chosen one see in figure 2 the extracted regions in white and in the lower left corner which color was selected. If one uses now the slider one can increase the range of the color. If the value is 10 and the chosen background color is [50 5 200] then the algorithm is also selecting every pixel with the colors between [40 0 190] and [60 15 210]. This is also seen in the lower left corner.  The buttom "next BG" can be used to select a second additional backgro...

Matlab: Image Processing: twelve-sided dice with numbers

Bild
( German ) This post is like the post before and describes the identification of the numbers on a twelve-sided dice with numbers from 1 to 12. Also automatically rolled by the dice rolling machine of  my brother . Dice identification: First of all the images are loaded into Matlab and the size is reduces to 200x200 pixel size. The with rgb2gray the image is reduces to a gray-scaled image and the gradient is used. The gradient and the normal image is converted into a binare image with a treshold. Then the gradient images is morphologically closed and multiplied with the normal tresholded image and afterwards morphologically dilated. After this the big for loop over all images is  executed. The the watershed is applied and the middle of the image with my own function is determined, which just calculate the mean of all columns and rows where the image is one. From this middle a big area is chosen that the rolled number is for sure in this area. Then the bigges...

Matlab: Image Processing: + and - identification on dices

Bild
( German ) This post describes the segmentation of images of dice with plus, minus and nothing on it Dice identification: My brother has built a dice rolling machine which automatically roll dices with 2/6 +, 1/6 - and 3/6 nothing on it. The images he produces automatically looked like this:  Here one can see that the + is in green and the - in red. Image Processing: First of all I loaded all images into Matlab and have cut them to a 200x200 size (second column). Further on I made a better contrast by multiplying all rgb-values with a factor, because the green plus and red minus had just a value of around 100 of 255 in rgb (third column). Then I splitted the channels in red, green and blue and generated out of this 3 channels on channel only red and only grenn by taken the red channel and subtracting the blue channel and the green channel with the factor 0.5. With a treshold in these images of 50 for green and 20 for red respectively I converted the images to binar...

Matlab: Segmentation Growing

Bild
Segmentation Growing ( German ) This post is about a methode of segmentation where a region is defined (seed) . In this seed the standard deviation and the mean is calculated and with a factor f it is weigthed. Pixel which are in the neighborhood of the seed are added to the seed if their value is in the boundary defined by the standard deviation, mean value and weighting factor f. This is done iterative as long as no more pixel is added to the seed. Then the object is segmented. function [region, area, seed, sx1, sx2, sy1, sy2] = Segmentation_Growing(img,sx1,sx2,sy1,sy2,f): This function needs an image as an imput. If there is no other input value one can choose with to cursors the starting point sx1, sy1, the left upper corner, and the end point sx2, sy2, the right lower corner. Otherwise one can define the s-value as one wants. If one uses cursors, one can use the second input argument for defining the factor f. This factor describes the weigthing and is in an area bigger equa...

Matlab: Dijkstra Methode - large neighborhood

Bild
The Dijkstra Methode - large neighborhood ( German )This is an update for the Dijkstra methode from the post before, where it uses now a larger neighborhood. It needs a bit longer but the probability to find the shortest path of many possible paths in the neighborhood is much higher. Here the comparing picture to Dijkstra Methode . Here one can download the following code on MathWorks: Source Code Dijkstra: function [path, prev, unvis, distance, start, target] = Dijkstra_Methode(Matrix, start, target) %Matrix is the incoming image %start is the start point in a vector [a,b] where a is the column and b the %row %target is the end point similare to start %path is the matrix with ones excepted at the position of the path where it is 0 %prev are also the previous visited pixels where the algorithm took the %wrong way %unvis are all unvisited pixels %distance is the distance or weight of the pixels %open the image and you can choose with the cursor the start %and end point if you d...

Matlab: Dijkstra methode - shortest way on gradient (small neighborhood)

Bild
The Dijkstra Methode ( German ) In this post i show you with Matlab how to calculate the shortest path on a gradient images with d´the dijkstra methode i wrote. I take an image as an input and convert it to an double and calculate the gradient [G,Gdir] = imgradient(img,'sobel'); and I use my function Dijkstra(G,p,q) : THis function needs a image as double G , a start value p and the target q , where the first entry of the oints is the column and the second the row. This methode sets all distances to infinity except the at the start value is zero obviously. All unvisited pixels have the value 1. The algortihm continous as long as the target is an unvisible pixel. For all neighborhood pixels the weights are calculated with the function [weight] = localedgewidth(G,p,q) ,where the value of the neightbor pixel is substract by the maximum of the matrix and devided by the difference of maximal and minimal value of the matrix G and multiplied with the distance to the neighbor pi...

Matlab: GUI Interface

Bild
Generating a GUI interfaces ( German ) In this post I show you how to generate a GUI interface with Matlab with buttons, checkboxes ... There one has to write "guide" in the console of Matlab and a window opens where you can create a new interface or load an old one. Now an editor opens where you easily can put the objects you want in. You can safe it an then the Matlab code is generated. To program it, it is important that you relate to each object an "tag". This you can do by double click on the object. An Inspector opens where you can edit it an other things like the "value", "name" or the design: Now one can push the green arrow to generate the code where you can define your functions: Programmieren des GUI interfaces The button can be programmed in the code under "function pushbutton1_Callback(hObject, eventdata, handles)". In this case the program generates a coil in "axes1" in dependence of the value in ...