find fingertips and valley point of hand in MATLAB - image

I am working on palm print identification by palm texture and geometry.
During the preprocessing step I want to detect fingertips and valley points of the hands. First we must find reference point for the trace bounding integer, after that find valley and fingertips point.
I was wondering if someone is able to help me.
This is my code:
I=imread(palm.jpg);
I=I(:,:,1);
h = fspecial('disk',30);
s = imfilter(I,h,'symmetric');
I1=s(:,:,1)>79;
I4=edge(I1,'canny');
%% find refrense point
s=size(I4);
r=[0,0];
for row=s(1):-1:1
for col=1:s(2)
if I4(row,col)==1
r=[row,col];
break
end
end
if I4(row,col)==1
r=[row,col];
break
end
end
b = bwtraceboundary(I4,[row col],'NW',8);

Related

How to block possibility to edit/drag impoly in matlab?

I create a polygon on image_area in matlab.
I used impoly.
But after creation polygon.
I need to block possibility to move and drag impoly (ROI is already created).
I don't know how I should do it ?
I would appreciate for any help please.
You can set the makeConstrainToRectFcn such that it is a rectangle encompassing your ROI, then whenever you try to move the latter it won't work. You can also, after creating the ROI, set the setVerticesDraggable method to false in order to prevent vertices from being dragged.
Sample code (adapted from example by the Mathworks):
clc
clear
figure
imshow('gantrycrane.png');
h = impoly(gca, [188,30; 189,142; 93,141; 13,41; 14,29]);
%// Get currentposition
Pos = getPosition(h);
%// Prevent draggable vertices
setVerticesDraggable(h,0);
%// Set up rectangle to prvent movement of ROI
fcn = makeConstrainToRectFcn('impoly', [min(Pos(:,1)) max(Pos(:,1))], [min(Pos(:,2)) max(Pos(:,2))]);
%// Apply function
h.setPositionConstraintFcn(fcn);
which results in this kind of situation (with red rectangle for illustration):

How to create a floor with Chipmunk library

I'm using Ruby and, of course, the Ruby bindings to Chipmunk as well as the Chingu/Gosu game libraries. Seems like the syntax is different but otherwise I assume it's the same as Chipmunk C. How do I make a floor? I tried the following:
space = CP::Space.new
space.damping = 0.9
space.gravity = CP::Vec2.new(0, 50)
body = CP::StaticBody.new
shape_array = [CP::Vec2.new(0, 400), CP::Vec2.new($window.width, 400), CP::Vec2.new($window.width, 390), CP::Vec2.new(0, 390)]
shape = CP::Shape::Poly.new(body, shape_array, CP::Vec2.new(0,0))
shape.collision_type = :floor
space.add_body(body)
space.add_shape(shape)
What happens is objects hit the floor and kind of wiggle for a split second, then pass right through. I want them to land on the floor, maybe even bounce up a little (depending on the object). But not go through the floor. How do I do this?
To make this work, I had to remove the line:
space.add_body(body)
Static bodies can't be added to space.

First pixel of the image

I just scanned a sample image and I'm trying to detect the first pixel which has a value of "0" in the binary-image.
I used paint to write a text and when i used the following prog, it always catches the bottom most pixel.
clear all;
x=imread('textjay.png');
y=im2bw(x);
height=size(y,1); % row
width=size(y,2); % col
valueoftheindex=0;
pixel_value=0;
for i=1:width
for j=1:height
pixel_value=y(j,i);
if (pixel_value==0)
valueofthewidth=i;
valueofthehieght=j;
break
end
end
end
valueofthewidth
valueofthehieght
imtool(y)
This depends a lot on what you consider to be "the first pixel".
Assuming that you can live with the pixel order that MATLAB assigns you could use
idx = find(y == 0, 1, 'first')
[row_idx, col_idx] = ind2sub(size(y), idx)
For other measures of "firstness" you would have to either transpose the input matrix (the image), or resort to some more refined way of calculation.
And yes, the break will only break the inner loop, as dawe already pointed out.

How to zoom to fit in WP7 Bing Maps control using LocationCollection?

How can I zoom the Microsoft.Phone.Controls.Maps.Map control to the correct zoom level on Windows Phone 7?
I have a LocationCollection of GeoCoordinates and I calculated the Center myself, but now how do I calculate the correct zoom level to fit the LocationCollection?
P.S. Is there an out of the box method to calculate the center of GeoCoordinates so I don't have to calculate it myself?
EDIT:
I've found another fine solution: http://4mkmobile.com/2010/09/quick-tip-position-a-map-based-on-a-collection-of-pushpins/
map.SetView(LocationRect.CreateLocationRect(points));
You can use the following code to calculate the LocationRect that bounds a set of points, and then pass the LocationRect to the SetView() method on the map control:
var bounds = new LocationRect(
points.Max((p) => p.Latitude),
points.Min((p) => p.Longitude),
points.Min((p) => p.Latitude),
points.Max((p) => p.Longitude));
map.SetView(bounds);
The map control handles animating from the current position to the new location.
NOTE: You'll need a using statement for System.Linq to get the Min and Max methods.
Derek has already given the answer so you should accept his, I offer an alternative code for cases where there many points. This approach only iterates the points collection once instead 4 times however it isn't as asthetically pleasing.
double north, west, south, west;
north = south = points[0].Latitude;
west = east = points[0].Longitude;
foreach (var p in points.Skip(1))
{
if (north < p.Latitude) north = p.Latitude;
if (west > p.Longitude) west = p.Longitude;
if (south > p.Latitude) south = p.Latitude;
if (east < p.Longitude) east = p.Longitude
}
map.SetView(new LocationRect(north, west, south, east));
As suggested by the other answers I use SetView with a LocationRect.
However I found that it always produces to low zoom level, since only integer values was used. If for instance the perfect zoom level would be 5.5, you would get 5.0. To get a proper fit I calculate a new zoom level from TargetZoomLeveland TargetBoundingRectangle:
viewRect = LocationRect.CreateLocationRect(coordinates);
map.SetView(viewRect);
double scale = map.TargetBoundingRectangle.Height/viewRect.Height;
map.ZoomLevel = map.TargetZoomLevel + Math.Log(scale, 2);
This example sets the zoom level to fit viewRect's height on the screen.

Sum up Area for material in Components, Google Sketchup

I am making a plugin to sum up the area of all the material in a Sketch.
I have succeeded in getting all the faces and such, but now the Components come into the picture.
Im using the term single or multi leveled component as i dont know any better way to explain the occurence of having a component inside an component and so on.
I have noticed that some components also have more to i than just 1 level. So if you go inside one component there may be components embedded inside this component that also have materials. So what i want is to sum up all of the material of a specific component and get all the "recursive" materials, if any, inside the component.
So, how do I count the area of all the material inside an component(single or multileveled)?
Here is what I would do, let's suppose that you loop through all entities and check for type of entity.
if entity.is_a? Sketchup::ComponentInstance
entity.definition.entities.each {|ent|
if ent.is_a? Sketchup::Face
#here do what you have to do to add area to your total
end
}
end
You can do the same with a Group with:
if entity.is_a? Sketchup::Group
entity.entities.each {|ent|
if ent.is_a? Sketchup::Face
#here do what you have to do to add area to your total
end
}
end
Hope it helps
Ladislav
Ladislav's example doesn't dig into all the levels.
For that you need a recursive method:
def sum_area( material, entities, tr = Geom::Transformation.new )
area = 0.0
for entity in entities
if entity.is_a?( Sketchup::Group )
area += sum_area( material, entity.entities, tr * entity.transformation )
elsif entity.is_a?( Sketchup::ComponentInstance )
area += sum_area( material, entity.definition.entities, tr * entity.transformation )
elsif entity.is_a?( Sketchup::Face ) && entity.material == material
# (!) The area returned is the unscaled area of the definition.
# Use the combined transformation to calculate the correct area.
# (Sorry, I don't remember from the top of my head how one does that.)
#
# (!) Also not that this only takes into account materials on the front
# of faces. You must decide if you want to take into account the back
# size as well.
area += entity.area
end
end
area
end

Resources