Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Replies: 0

 john john Posts: 18 Registered: 6/22/11
Posted: Feb 7, 2012 8:51 AM

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 = http://i1065.photobucket.com/albums/u390/myjonas1990/ORIGINALINPUT.jpg
output image = http://i1065.photobucket.com/albums/u390/myjonas1990/OUTPUTBW2.jpg

Refer the code below I am using..
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', ...
'Replicates',2);
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;
end
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) );
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
if(sample_height>50)
N = N(1:50,:);
end
if(sample_width>50)
N = N(:,1:50);
end
[sample_height sample_width] = size(N);
[sample_height sample_width] = size(N);
else
end
%this two lines is for debugging purpose only
imshow(L);
hold on;
plot(centroid_x, centroid_y, 'bo');
rectangle('Position', [ cropped_x cropped_y cropped_w cropped_h ], 'EdgeColor','y');
hold off;
croppedImage = N;