The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Please Help Me To Crop This hand signal on this region?
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
john john

Posts: 18
Registered: 6/22/11
Please Help Me To Crop This hand signal on this region?
Posted: Feb 7, 2012 8:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Please Help Me To Crop This hand signal on this region? I am doing hand signal recognition, I already track the hand, make it black and white the image, I already mark the main image to be crop.. now what I want is to control region being crop in the image..what i want is to crop the region shown in the image(i put a line)....(see this links below) How do I do that? refer the Code Below...
input image =
output image =

Refer the code below I am using..
x = imread('C:\Users\Jonas Mamaran\Documents\MATLAB\pray\a\akugangsss.jpg');
rawImage = x;
I = rawImage;
cform = makecform('srgb2lab');
J = applycform(I,cform);
ab = double(J(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 2;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
pixel_labels = reshape(cluster_idx,nrows,ncols);
segmented_images = cell(1,2);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = I;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
mean_cluster_value = mean(cluster_center,2);
[tmp, idx] = sort(mean_cluster_value);
hand_cluster_num = idx(2);
K = segmented_images{hand_cluster_num};
L = im2bw(segmented_images{hand_cluster_num},0.001);
s = regionprops(rgb_label, I, {'Centroid','BoundingBox'});
% s(hand_cluster_num).Centroid
% s(hand_cluster_num).BoundingBox
centroid_x = uint16(s(hand_cluster_num).Centroid(1));
centroid_y = uint16(s(hand_cluster_num).Centroid(2));
cropped_x = uint16(s(hand_cluster_num).BoundingBox(1))+1;
cropped_y = uint16(s(hand_cluster_num).BoundingBox(2))+1;
cropped_w = uint16(s(hand_cluster_num).BoundingBox(4))-2;
cropped_h = uint16(s(hand_cluster_num).BoundingBox(5))-2;
% apply gaussian blur to remove noise
PSF = fspecial('gaussian',7,10);
L = imfilter(L,PSF,'symmetric','conv');
% cropped region of interest from main image
M = L( cropped_y : (cropped_y+cropped_h), cropped_x: (cropped_x+cropped_w) );
% trim leading and leading zeroes
M(:, logical(sum(abs(M)) == 0)) = [];
cropped_h = size(M,1);
cropped_w = size(M,2);
non_zeroes = find(sum(abs(L))~=0);
cropped_x = non_zeroes(1);
% fill holes to remove flares
M = imfill(M, 'holes');
% get a shrunk sample from cropped image
N = imresize(M, 0.25);
[sample_height sample_width] = size(N);
% clip excess pixels
N = N(1:50,:);
N = N(:,1:50);
[sample_height sample_width] = size(N);
%pad both sides
htopad = double(25 - ceil(sample_height/2));
wtopad = double(25 - ceil(sample_width/2));
N = padarray(N,[htopad wtopad]);
%for uneven padding, add padding to end
[sample_height sample_width] = size(N);
htopad = 50 - sample_height;
wtopad = 50 - sample_width;
N = padarray(N,[htopad wtopad],0,'post');
disp('Padding not performed...');
%this two lines is for debugging purpose only
hold on;
plot(centroid_x, centroid_y, 'bo');
rectangle('Position', [ cropped_x cropped_y cropped_w cropped_h ], 'EdgeColor','y');
hold off;
croppedImage = N;

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.