Prev: ordinary least squares, complex number matrix and real parameter
Next: Can you use MFC functions/libraries with s-functions and MEX compiler?
From: Nehal on 2 Jul 2010 09:55 "Nehal " <arnab620(a)yahoo.com> wrote in message <i0kodg$104$1(a)fred.mathworks.com>... > "Christopher " <christopher.badman(a)au.saabgroup.com> wrote in message <i0k46q$9vt$1(a)fred.mathworks.com>... > > "Nehal " <arnab620(a)yahoo.com> wrote in message <i0jv79$mtq$1(a)fred.mathworks.com>... > > > > When you say 'crop', do you mean that you want to minimise the image frame so that only the white hand remains? Or do you want to retrieve the hand from the original image and leave the background black? > > > > For the first solution, use regionprops(): > > > > % black and white image named BW > > elements = regionprops(BW,'Area','BoundingBox'); > > > > % possible that more than one element exists, if this is the case, assume hand is the > > % largest > > areaArray = zeros(1,length(elements)); > > for i = 1:length(elements) > > areaArray(i) = element(i).Area; > > end > > > > % index will point to your hand object > > [maxArea, index] = max(areaArray); > > > > % now get the bounding box of the hand > > boxParams = elements(index).BoundingBox; > > > > % now crop according to your parameters! > > croppedIm = BW(boxParams(1):boxParams(1)+boxParams(3), boxParams(2):boxParams(2)+boxParams(4)); > > > > > > Chris I have tried... BW=imread (the image); then executed all the code line by line provided by you... then when i try to see the "croppedIm"... it shows nothing... what am I doing wrong...?
From: Image Analyst on 2 Jul 2010 12:56 Maybe it's displaying it in the range 0-255. did you try to display it like this: imshow(croppedIm, []); % Note the use of [] to scale for display.
From: Nehal on 2 Jul 2010 13:11 "Image Analyst" <imageanalyst(a)mailinator.com> wrote in message <i0l5n4$dd4$1(a)fred.mathworks.com>... > Maybe it's displaying it in the range 0-255. did you try to display it like this: > imshow(croppedIm, []); % Note the use of [] to scale for display. OKey... i am posting what i have done and what it's saying.... clear all BW=imread('sample_tif.tif'); % black and white image named BW elements = regionprops(BW,'Area','BoundingBox'); % possible that more than one element exists, if this is the case, assume hand is the % largest areaArray = zeros(1,length(elements)); for i = 1:length(elements) areaArray(i) = elements(i).Area; end % index will point to your hand object [maxArea, index] = max(areaArray); % now get the bounding box of the hand boxParams = elements(index).BoundingBox; % now crop according to your parameters! croppedIm = BW(boxParams(1):boxParams(1)+boxParams(3), boxParams(2):boxParams(2)+boxParams(4)); Warning: Integer operands are required for colon operator when used as index Warning: Integer operands are required for colon operator when used as index there r 2 warnings... what does it mean...? and... imshow(croppedIm, []); what value should i use in []..? i hav tried some.. bt still not working.
From: ImageAnalyst on 2 Jul 2010 17:12 You need to round the bounding box coordinates - it's giving you non- integer values (long story...). That's why I didn't mention that method. I was going to suggest using any() in each direction and then using find() to find the first and last index in each direction. If you want to try it that way, and can't figure it out on your own, let me know. You don't put anything in the [] and then it will find the min and max itself and map the min to 0 and the max to 255. For the binary image you have, it will leave 0 as 0 and make all the 1's 255 so you can then see them.
From: Nehal on 3 Jul 2010 00:55
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <bbdeaa8e-e6fe-4c8c-a606-b28478fe3836(a)d8g2000yqf.googlegroups.com>... > You need to round the bounding box coordinates - it's giving you non- > integer values (long story...). That's why I didn't mention that > method. I was going to suggest using any() in each direction and then > using find() to find the first and last index in each direction. If > you want to try it that way, and can't figure it out on your own, let > me know. > > You don't put anything in the [] and then it will find the min and max > itself and map the min to 0 and the max to 255. For the binary image > you have, it will leave 0 as 0 and make all the 1's 255 so you can > then see them. sorry..didn't understand the method... either way.. i need it to be done... so it would be a great help if you could fix the 1st code or help me with the process that you mentioned in your last post... NB: i am a beginner. that's why i think i am not understanding most of the things you r saying... sorry... :) |