I have some isssue with my codes
3 views (last 30 days)
Show older comments
Hi everyone . I would like to ask for help ,instruction and feedback , I would like to make a convex hull for hand gesture in real time , basically I have done the color segmentation of the skin and I create of function of the result and now I'm stuck with the convex hull algortihm . is shows I have an error on the line 9 of the code and I.m about confused and I do not know what steps to take .
Picture
Code for segmentation using graph cut in matlab btw if is any other technique better than this let me know
This is to shwo me the pictures .
clc
clear all %#ok<CLALL>
close all
RGB=imread('hand2.jpg');
imshow(RGB);
subplot(1,3,1);
imshow(RGB);
title('Original Image');
[BW,maskedImage]=segmentImage(RGB);
subplot(1,3,2);
imshow(BW);
title('Segmented Binary Image ');
subplot(1,3,3);
imshow(maskedImage);
title('Segmented Color Image');
Function for graph cut is :
function [BW,maskedImage] = segmentImage(RGB);
%segmentImage Segment image using auto-generated code from imageSegmenter app
% [BW,MASKEDIMAGE] = segmentImage(RGB) segments image RGB using
% auto-generated code from the imageSegmenter app. The final segmentation
% is returned in BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 22-Feb-2021
%----------------------------------------------------
% Convert RGB image into L*a*b* color space.
X = rgb2lab(RGB);
% Graph cut
foregroundInd = [158384 161690 173774 174914 177198 178226 184853 189269 189275 189284 191472 192569 194775 195900 198108 204706 211413 212472 212516 215754 215792 219117 221257 231258 232304 232313 234499 234508 234515 234516 234521 234584 237896 241176 247735 248843 248854 248933 251047 254360 257680 257715 258861 261017 264350 264353 265399 265445 265455 271016 272020 274268 275414 277586 284158 285327 285362 288672 291924 295207 300712 300773 301904 304058 304130 307298 310690 310691 310739 311795 315055 321718 323857 324986 330635 331706 331710 333933 335022 335052 338228 339382 339413 341590 341625 342729 342743 342749 344943 344975 349349 349352 351514 351515 352565 354778 355934 355986 358081 358221 361450 364756 365812 369191 371329 371439 374801 375855 377998 378063 378113 379052 379102 381359 382412 384737 385733 387880 387999 389082 392291 394579 394623 395663 395669 397807 398914 398954 398977 398986 399078 399090 402214 402311 404417 404473 404479 405517 405535 405590 407797 408875 408969 411034 411088 411216 412154 412228 414343 414436 417650 417743 417797 420959 422060 422135 422183 424292 424369 425525 428753 428807 428847 430984 432062 434200 435303 435326 435406 438724 438774 438836 440818 441011 442006 442085 442095 444288 445233 445259 445342 445343 445345 445460 448627 448704 450751 450775 450829 450833 450853 451942 451943 454150 455163 455189 458579 460708 461782 465124 465275 465327 467330 468402 468433 470720 471711 471814 474156 475052 475217 475260 477229 478363 478524 478572 480570 480571 480653 480731 481639 481671 481739 481827 483846 483953 484049 484980 485057 485078 485139 487186 488260 488353 488447 488448 489511 489546 491601 491686 491690 491701 492673 492702 492878 492879 494978 495013 495075 496012 496102 496184 498219 499293 499415 499493 501622 501714 502602 502632 502744 502780 505941 508243 508261 508301 509371 509404 509420 511431 511459 511635 512736 514770 514864 514919 515844 516041 516048 516050 516119 518079 518210 519280 521362 521388 521595 521598 521642 522586 522701 524673 524842 524861 524867 525801 525922 525947 525956 525999 528007 528104 528166 528203 529084 531291 531492 531497 531525 532420 532520 532688 534598 534627 534766 535698 537894 537897 537898 537901 537904 537937 538093 538996 539040 539256 539315 541203 541248 541349 542304 542305 542349 544510 544557 544838 545614 545770 547821 547822 548150 548925 548970 551133 551178 551282 551402 552237 552280 552506 554445 555549 555550 555553 555555 555558 555561 555562 555565 555570 555571 555573 555577 555580 555585 555588 555591 557903 557965 559130 564589 564713 565631 565693 565754 567850 568952 568960 571213 571338 572273 574525 574587 578875 578885 578941 582208 584404 585511 585565 585627 585696 587705 587716 588809 591085 591218 595501 598742 598880 601021 604262 604470 607646 610885 614339 617506 617584 618610 621920 622134 627440 627593 628760 630833 630905 634145 635168 637457 637593 639584 641792 648416 648575 649520 649679 651728 652915 658352 661664 662768 665136 666080 669478 671600 674998 676016 681536 686041 688160 691632 694786 694944 698186 704722 712541 714658 715855 719074 721282 722386 725698 725791 728070 729106 729174 734627 735732 741155 744564 748982 751190 754502 755606 758918 761126 762230 ];
backgroundInd = [151950 151978 158544 164146 166929 170670 176856 185004 188057 189472 189474 189495 191661 191670 191730 192756 192760 192883 195028 195062 196066 198271 201704 202683 206040 208195 208339 209326 209456 209458 211489 211672 211678 211679 211681 212607 212749 214368 215913 222129 222532 225840 231517 232459 235776 235934 235936 238144 239134 241299 241451 244597 244615 244696 245698 249042 252367 254690 257841 257898 257996 261328 264622 264626 267850 268948 268953 268954 271152 271153 271155 271156 272247 274396 274549 275653 278376 278863 281065 282178 282180 284377 285436 287697 287700 288748 292228 292235 292237 292244 295417 295535 297631 298732 300892 300942 302159 302189 308620 315286 315407 317454 318120 318595 318715 318760 321432 325225 327390 334053 337441 341742 349679 354990 355033 362836 367857 371587 372691 374411 374862 375023 378840 386016 390969 391422 394857 402462 402647 409086 415776 427500 431169 431281 434548 440648 443960 445525 448376 448834 451192 457725 457796 458899 465399 472098 474437 475393 475440 480858 480913 480991 484881 488196 489748 492001 492047 492610 494956 495211 495352 496058 496060 496392 498268 498583 499363 499364 501569 501571 501900 501901 502670 502989 504874 504875 505978 509288 511821 512877 518116 521426 525868 526307 531361 531649 537983 541324 542396 545708 549049 551257 551604 552359 554538 558062 558207 558980 559166 561160 561374 561463 562478 564472 568915 569105 569381 571095 571314 571489 572418 574435 574626 577940 581026 581056 582357 582441 585669 585807 587747 588754 588851 588984 590990 591192 592163 592289 594371 594719 595403 595475 595610 597818 598687 598714 598787 599070 600920 601209 602023 604307 605160 605411 605547 607368 607619 608645 608723 608783 609116 610931 611784 611934 612035 614165 614243 615346 615347 615561 617552 618556 618581 618783 620864 621009 621968 621971 624581 625205 625280 627488 627491 627557 627892 628489 628592 628719 628739 628809 630800 630869 631829 631904 634112 634115 634181 634516 635617 637551 637828 638453 638598 639384 639632 639635 639702 639782 641840 641910 642944 643014 645152 646326 648358 648464 648617 648681 649493 649568 649571 649695 651528 651776 651849 652880 653007 655091 655215 655242 658473 658705 659504 659507 661712 661785 661868 665024 665099 665151 666128 666285 668261 668336 668411 668463 668493 669330 669443 669515 669567 669657 671648 671775 672507 672755 674960 675117 676064 676140 676193 676415 678197 678275 679376 679533 681660 681801 682691 684896 685026 686078 686157 686171 688135 688208 688338 689315 691404 691523 692387 692624 692702 692836 694759 694835 695028 695037 695936 696071 696093 699248 699251 699327 701383 702560 702639 702717 704768 704904 705872 705878 705953 708007 708080 708216 708936 709265 709341 709526 711268 711473 712248 712269 712496 712577 712580 712635 712653 714703 714704 714785 715735 715816 715892 718015 718097 719119 719201 719204 719261 719277 719431 721409 722360 722429 722513 722574 722745 722748 722761 724637 724721 725753 725901 728036 728096 729053 729140 731050 731133 731273 731348 732298 734661 735674 735765 737973 738035 738793 738986 739003 741285 741287 742297 742391 744364 744659 744668 745446 745546 745609 745704 745763 748919 749019 749075 751126 751227 752230 752254 752333 752387 754541 754595 757854 757907 758851 758958 759011 761003 761166 761219 761226 762191 762281 764368 765470 765603 767790 768894 768954 770941 770986 771026 771137 772206 772265 774340 774456 774462 774468 775444 775520 777607 777655 778669 778832 780917 781040 781984 782018 782074 782141 785296 785327 785450 788756 789808 791921 793167 793169 795235 795257 796339 796436 796475 798550 798566 798644 799657 799661 799751 799753 799784 803071 803076 803078 803082 803085 803088 803090 803094 ];
L = superpixels(X,4671,'IsInputLab',true);
% Convert L*a*b* range to [0 1]
scaledX = prepLab(X);
BW = lazysnapping(scaledX,L,foregroundInd,backgroundInd);
% Create masked image.
maskedImage = RGB;
maskedImage(repmat(~BW,[1 1 3])) = 0;
end
function out = prepLab(in)
% Convert L*a*b* image to range [0,1]
out = in;
out(:,:,1) = in(:,:,1) / 100; % L range is [0 100].
out(:,:,2) = (in(:,:,2) + 86.1827) / 184.4170; % a* range is [-86.1827,98.2343].
out(:,:,3) = (in(:,:,3) + 107.8602) / 202.3382; % b* range is [-107.8602,94.4780].
end
Now is the convex hull that I wanna implemented . please tell me where is the mistake
2 Comments
Answers (3)
Alexandru Burghelea
on 4 Mar 2021
1 Comment
Walter Roberson
on 4 Mar 2021
clc
clear all %#ok<CLALL>
close all
RGB=imread('hand2.jpg');
imshow(RGB);
subplot(1,3,1);
imshow(RGB);
title('Original Image');
[BW,maskedImage]=segmentImage(RGB);
subplot(1,3,2);
imshow(BW);
title('Segmented Binary Image ');
subplot(1,3,3);
imshow(maskedImage);
title('Segmented Color Image');
%Function for graph cut is :
function [BW,maskedImage] = segmentImage(RGB);
%segmentImage Segment image using auto-generated code from imageSegmenter app
% [BW,MASKEDIMAGE] = segmentImage(RGB) segments image RGB using
% auto-generated code from the imageSegmenter app. The final segmentation
% is returned in BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 22-Feb-2021
%----------------------------------------------------
% Convert RGB image into L*a*b* color space.
X = rgb2lab(RGB);
% Graph cut
foregroundInd = [158384 161690 173774 174914 177198 178226 184853 189269 189275 189284 191472 192569 194775 195900 198108 204706 211413 212472 212516 215754 215792 219117 221257 231258 232304 232313 234499 234508 234515 234516 234521 234584 237896 241176 247735 248843 248854 248933 251047 254360 257680 257715 258861 261017 264350 264353 265399 265445 265455 271016 272020 274268 275414 277586 284158 285327 285362 288672 291924 295207 300712 300773 301904 304058 304130 307298 310690 310691 310739 311795 315055 321718 323857 324986 330635 331706 331710 333933 335022 335052 338228 339382 339413 341590 341625 342729 342743 342749 344943 344975 349349 349352 351514 351515 352565 354778 355934 355986 358081 358221 361450 364756 365812 369191 371329 371439 374801 375855 377998 378063 378113 379052 379102 381359 382412 384737 385733 387880 387999 389082 392291 394579 394623 395663 395669 397807 398914 398954 398977 398986 399078 399090 402214 402311 404417 404473 404479 405517 405535 405590 407797 408875 408969 411034 411088 411216 412154 412228 414343 414436 417650 417743 417797 420959 422060 422135 422183 424292 424369 425525 428753 428807 428847 430984 432062 434200 435303 435326 435406 438724 438774 438836 440818 441011 442006 442085 442095 444288 445233 445259 445342 445343 445345 445460 448627 448704 450751 450775 450829 450833 450853 451942 451943 454150 455163 455189 458579 460708 461782 465124 465275 465327 467330 468402 468433 470720 471711 471814 474156 475052 475217 475260 477229 478363 478524 478572 480570 480571 480653 480731 481639 481671 481739 481827 483846 483953 484049 484980 485057 485078 485139 487186 488260 488353 488447 488448 489511 489546 491601 491686 491690 491701 492673 492702 492878 492879 494978 495013 495075 496012 496102 496184 498219 499293 499415 499493 501622 501714 502602 502632 502744 502780 505941 508243 508261 508301 509371 509404 509420 511431 511459 511635 512736 514770 514864 514919 515844 516041 516048 516050 516119 518079 518210 519280 521362 521388 521595 521598 521642 522586 522701 524673 524842 524861 524867 525801 525922 525947 525956 525999 528007 528104 528166 528203 529084 531291 531492 531497 531525 532420 532520 532688 534598 534627 534766 535698 537894 537897 537898 537901 537904 537937 538093 538996 539040 539256 539315 541203 541248 541349 542304 542305 542349 544510 544557 544838 545614 545770 547821 547822 548150 548925 548970 551133 551178 551282 551402 552237 552280 552506 554445 555549 555550 555553 555555 555558 555561 555562 555565 555570 555571 555573 555577 555580 555585 555588 555591 557903 557965 559130 564589 564713 565631 565693 565754 567850 568952 568960 571213 571338 572273 574525 574587 578875 578885 578941 582208 584404 585511 585565 585627 585696 587705 587716 588809 591085 591218 595501 598742 598880 601021 604262 604470 607646 610885 614339 617506 617584 618610 621920 622134 627440 627593 628760 630833 630905 634145 635168 637457 637593 639584 641792 648416 648575 649520 649679 651728 652915 658352 661664 662768 665136 666080 669478 671600 674998 676016 681536 686041 688160 691632 694786 694944 698186 704722 712541 714658 715855 719074 721282 722386 725698 725791 728070 729106 729174 734627 735732 741155 744564 748982 751190 754502 755606 758918 761126 762230 ];
backgroundInd = [151950 151978 158544 164146 166929 170670 176856 185004 188057 189472 189474 189495 191661 191670 191730 192756 192760 192883 195028 195062 196066 198271 201704 202683 206040 208195 208339 209326 209456 209458 211489 211672 211678 211679 211681 212607 212749 214368 215913 222129 222532 225840 231517 232459 235776 235934 235936 238144 239134 241299 241451 244597 244615 244696 245698 249042 252367 254690 257841 257898 257996 261328 264622 264626 267850 268948 268953 268954 271152 271153 271155 271156 272247 274396 274549 275653 278376 278863 281065 282178 282180 284377 285436 287697 287700 288748 292228 292235 292237 292244 295417 295535 297631 298732 300892 300942 302159 302189 308620 315286 315407 317454 318120 318595 318715 318760 321432 325225 327390 334053 337441 341742 349679 354990 355033 362836 367857 371587 372691 374411 374862 375023 378840 386016 390969 391422 394857 402462 402647 409086 415776 427500 431169 431281 434548 440648 443960 445525 448376 448834 451192 457725 457796 458899 465399 472098 474437 475393 475440 480858 480913 480991 484881 488196 489748 492001 492047 492610 494956 495211 495352 496058 496060 496392 498268 498583 499363 499364 501569 501571 501900 501901 502670 502989 504874 504875 505978 509288 511821 512877 518116 521426 525868 526307 531361 531649 537983 541324 542396 545708 549049 551257 551604 552359 554538 558062 558207 558980 559166 561160 561374 561463 562478 564472 568915 569105 569381 571095 571314 571489 572418 574435 574626 577940 581026 581056 582357 582441 585669 585807 587747 588754 588851 588984 590990 591192 592163 592289 594371 594719 595403 595475 595610 597818 598687 598714 598787 599070 600920 601209 602023 604307 605160 605411 605547 607368 607619 608645 608723 608783 609116 610931 611784 611934 612035 614165 614243 615346 615347 615561 617552 618556 618581 618783 620864 621009 621968 621971 624581 625205 625280 627488 627491 627557 627892 628489 628592 628719 628739 628809 630800 630869 631829 631904 634112 634115 634181 634516 635617 637551 637828 638453 638598 639384 639632 639635 639702 639782 641840 641910 642944 643014 645152 646326 648358 648464 648617 648681 649493 649568 649571 649695 651528 651776 651849 652880 653007 655091 655215 655242 658473 658705 659504 659507 661712 661785 661868 665024 665099 665151 666128 666285 668261 668336 668411 668463 668493 669330 669443 669515 669567 669657 671648 671775 672507 672755 674960 675117 676064 676140 676193 676415 678197 678275 679376 679533 681660 681801 682691 684896 685026 686078 686157 686171 688135 688208 688338 689315 691404 691523 692387 692624 692702 692836 694759 694835 695028 695037 695936 696071 696093 699248 699251 699327 701383 702560 702639 702717 704768 704904 705872 705878 705953 708007 708080 708216 708936 709265 709341 709526 711268 711473 712248 712269 712496 712577 712580 712635 712653 714703 714704 714785 715735 715816 715892 718015 718097 719119 719201 719204 719261 719277 719431 721409 722360 722429 722513 722574 722745 722748 722761 724637 724721 725753 725901 728036 728096 729053 729140 731050 731133 731273 731348 732298 734661 735674 735765 737973 738035 738793 738986 739003 741285 741287 742297 742391 744364 744659 744668 745446 745546 745609 745704 745763 748919 749019 749075 751126 751227 752230 752254 752333 752387 754541 754595 757854 757907 758851 758958 759011 761003 761166 761219 761226 762191 762281 764368 765470 765603 767790 768894 768954 770941 770986 771026 771137 772206 772265 774340 774456 774462 774468 775444 775520 777607 777655 778669 778832 780917 781040 781984 782018 782074 782141 785296 785327 785450 788756 789808 791921 793167 793169 795235 795257 796339 796436 796475 798550 798566 798644 799657 799661 799751 799753 799784 803071 803076 803078 803082 803085 803088 803090 803094 ];
L = superpixels(X,4671,'IsInputLab',true);
% Convert L*a*b* range to [0 1]
scaledX = prepLab(X);
BW = lazysnapping(scaledX,L,foregroundInd,backgroundInd);
% Create masked image.
maskedImage = RGB;
maskedImage(repmat(~BW,[1 1 3])) = 0;
end
function out = prepLab(in)
% Convert L*a*b* image to range [0,1]
out = in;
out(:,:,1) = in(:,:,1) / 100; % L range is [0 100].
out(:,:,2) = (in(:,:,2) + 86.1827) / 184.4170; % a* range is [-86.1827,98.2343].
out(:,:,3) = (in(:,:,3) + 107.8602) / 202.3382; % b* range is [-107.8602,94.4780].
end
Image Analyst
on 5 Mar 2021
To get the convex hull, call bwconvhull()
chImage = bwconvhull(BW);
There is an option to do the convex hulls of each region independently, or to take the convex hull of the whole collection of blobs in the binary image. Pick whichever one you want.
5 Comments
Image Analyst
on 5 Mar 2021
Dirk-Jan Kroon has lots of code in his File Exchange related to finding hands and fingers. I suggest you look it over:
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!