You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Average pixel color intensity of ROI
2 views (last 30 days)
Show older comments
For the attached image I am able to find pixel intensity of bowls one by one by selecting one bowl at a time. This is hectic, can u help to find pixel intensity seperatly of two bowls but in one go without seperating it into two images. Similarly I want to find the pixel intensity of two bowls in its hsv image.
Answers (1)
Image Analyst
on 24 Sep 2021
What do you mean by "intensity"? Do you mean the values in the V image?
You can use regionprops().
5 Comments
Apra Gupta
on 24 Sep 2021
Edited: Apra Gupta
on 24 Sep 2021
Intensity I mean every pixel repersent a color. I used the command mean2(RGB).
I studied about regionprops(), but could not use it.
Image Analyst
on 24 Sep 2021
See my Image Segmentation Tutorial
Apra Gupta
on 25 Sep 2021
Hi, I tried to run blob's demo for my images, but i not able to get BW image for any threshold, as there is no much difference between background and bowls and even between two bowls.
Basically it is not detecting only two bowls from whole image.
I need my program to detect two bowls from whole Image, and find the mean color intensity of each bowl seperatly.
Image Analyst
on 25 Sep 2021
I already gave you code to mask it, remember? That's how you got the images you attached to your original image. Why are you not using that code?
Apra Gupta
on 27 Sep 2021
Hi Sir, I tried using those masked images also to find the mean. But I am getting mean of whole image.
If I use regionprops it doesn't identify two bowls, rather lot many centroids. Conneccomp command is not able to identify one bowl whole as 1 component and 2nd bowl as another.
So i am seprating each image as attached and then finding mean of whole image as pixel color intensity of black background is zero so it will affect the average.
Can u provide any other easy approach?
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
RGB = imread('visi 10ml.png');
subplot(2, 2, 1);
imshow (RGB)
title('Original Image', 'fontSize', fontSize);
[mask, maskedRgbImage] = segmentImage(RGB);
subplot(2, 2, 2);
imshow(mask)
title('Mask Image', 'fontSize', fontSize);
subplot(2, 2, 3);
imshow(maskedRgbImage)
title('Masked RGB Image', 'fontSize', fontSize);
fprintf('Done with %s\n', mfilename);
mean = mean(maskedRgbImage(:));
disp(mean)
hp = impixelinfo();
% To set location of the status bar
hp.Position = [0.2, 0.4, 0.03, 0.4]; % xLeft, yBottom, width, height, all normalized 0-1.
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 23-Sep-2021
%----------------------------------------------------
% Convert RGB image into L*a*b* color space.
X = rgb2lab(RGB);
% Graph cut
foregroundInd = [3210315 3210318 3210322 3210325 3210327 3210330 3210332 3210337 3210339 3210344 3210347 3210351 3210354 3210363 3210366 3210371 3210373 3210378 3210383 3210388 3210392 3210395 3210397 3210404 3210407 3210414 3216056 3216058 3216172 3216174 3219881 3220013 3223701 3223705 3223708 3223713 3223850 3223855 3229608 3229613 3233273 3233450 3233454 3239205 3239207 3239210 3239212 3242851 3243051 3243056 3243059 3248585 3248592 3248807 3248809 3252646 3252651 3252653 3256241 3256485 3256487 3265814 3266067 3266070 3271823 3275655 3275662 3279214 3279496 3284952 3285247 3285249 3285252 3289084 3294834 3294836 3294841 3298350 3304426 3304431 3307930 3308265 3308270 3317505 3317722 3317742 3317763 3317773 3317857 3317860 3321330 3321335 3321535 3327363 3327445 3327447 3330900 3330903 3331286 3334727 3334732 3334942 3335036 3335121 3340466 3340473 3340475 3344290 3344298 3344510 3344623 3344703 3344705 3350456 3353856 3353858 3353863 3353866 3354208 3354288 3354290 3354293 3357681 3357683 3357688 3358130 3363424 3363880 3363882 3367241 3367246 3367253 3367714 3372980 3372982 3372987 3373240 3373375 3373462 3376812 3377297 3382555 3382560 3382958 3383045 3386879 3390217 3390219 3390624 3390711 3390714 3396462 3399792 3400011 3400209 3400296 3405771 3405957 3409369 3409630 3409794 3413628 3413631 3413713 3419195 3419381 3419384 3422965 3423223 3428522 3428976 3428978 3429043 3432617 3432815 3432880 3436181 3436348 3436657 3436661 3442417 3442462 3445759 3446258 3446261 3451796 3452014 3452047 3455339 3455848 3455855 3455858 3455879 3461080 3461606 3461635 3464912 3465440 3465442 3465467 3468744 3469274 3469301 3474484 3474487 3475025 3475054 3478309 3478311 3478601 3478857 3478886 3484057 3484605 3484634 3484636 3487884 3488041 3488232 3488437 3488468 3488473 3491707 3491714 3492269 3492271 3492305 3498019 3498053 3501287 3501854 3501887 3501892 3507341 3507640 3510855 3510859 3511434 3511472 3516600 3517182 3517223 3520427 3520599 3521018 3524257 3524850 3524892 3530171 3530640 3534167 3534472 3540220 3544013 3544052 3547884 3553151 3553639 3556839 3556846 3556858 3556872 3556889 3557471 3562584 3562649 3563011 3563219 3566409 3566411 3567005 3567051 3570234 3570241 3570883 3575982 3576324 3576631 3580463 3585562 3586165 3589394 3589509 3589850 3595289 3595791 3599623 3602798 3603411 3608546 3609205 3612378 3613037 3618126 3618785 3622436 3622574 3625790 3631538 3632154 3632197 3641118 3641734 3644950 3645566 3645609 3648782 3649446 3654530 3654670 3655146 3655194 3664110 3664726 3667942 3668435 3668606 3673881 3674296 3674354 3677522 3678188 3681354 3682020 3687102 3687768 3687773 3690934 3691605 3696682 3697107 3697131 3697153 3697278 3700514 3701185 3704720 3704749 3704829 3704935 3710765 3713926 3714305 3714597 3714600 3719674 3720348 3724184 3729254 3729385 3729481 3729751 3729932 3733086 3733405 3733637 3736918 3737596 3743344 3746998 3747176 3752246 3752760 3752924 3756756 3759910 3760381 3760410 3760588 3765658 3765933 3766093 3766158 3766339 3769886 3770171 3775620 3775919 3775924 3779070 3779756 3783402 3783588 3788986 3789336 3792482 3792613 3792979 3793168 3798230 3798916 3802062 3802309 3802376 3802550 3808223 3808496 3808498 3811642 3812106 3812335 3815904 3815974 3816169 3821485 3821519 3821917 3825054 3825754 3831027 3831164 3831167 3831172 3831179 3831203 3831502 3834634 3834774 3835334 3838744 3844214 3844914 3848046 3848404 3848746 3854494 3857626 3858063 3858329 3861458 3861808 3862161 3867909 3871038 3871741 3876786 3876844 3877245 3880679 3881321 3886366 3886427 3886620 3887069 3890259 3890592 3890693 3890901 3894030 3894096 3894455 3894733 3899844 3900481 3903606 3903806 3903958 3904313 3909354 3909426 3909829 3910061 3913186 3913263 3913893 3917018 3917189 3917392 3917406 3917498 3917725 3923128 3923173 3923473 3926677 3926841 3926916 3927305 3932346 3932806 3932826 3933053 3936453 3936614 3941923 3942010 3942278 3942633 3945755 3946112 3949587 3949821 3949833 3950060 3950297 3955429 3955523 3955560 3955818 3959167 3959271 3965398 3965625 3968747 3969215 3973289 3978327 3982524 3987907 3988390 3988617 3991739 3991973 3992087 3996051 3996281 4001802 4002029 4005368 4005636 4005861 4010899 4011609 4015108 4015441 4020479 4020834 4021189 4024654 4028143 4028346 4028635 4034364 4034388 4034601 4037892 4038201 4038430 4043471 4043961 4043963 4044178 4047303 4047513 4047701 4048010 4051623 4060715 4061195 4066463 4066885 4067170 4070638 4070664 4070725 4071002 4074127 4074337 4074354 4074595 4074634 4079875 4080322 4080346 4083707 4084074 4084414 4089455 4089675 4090162 4093287 4093504 4093994 4099035 4099400 4099542 4102867 4103229 4103328 4103574 4106699 4106916 4107044 4107061 4107199 4107201 4107203 4107406 4112447 4112898 4113154 4116639 4116776 4116986 4122734 4125859 4126091 4126108 4126211 4126238 4126566 4129691 4130043 4130133 4130171 4130398 4135688 4136146 4139271 4139616 4139640 4139973 4145258 4145282 4145410 4145441 4145478 4148851 4149187 4149551 4154935 4155299 4158431 4158709 4158721 4158728 4158735 4158752 4158759 4159131 4162673 4162690 4168711 4171843 4172010 4172140 4177591 4177845 4178286 4181809 4185950 4191006 4191264 4191327 4191372 4191698 4194838 4195183 4195530 4201276 4204418 4204813 4205108 4208250 4208940 4213998 4214683 4218206 4223582 4224260 4227414 4228092 4233162 4233447 4236994 4237665 4240826 4241126 4241497 4246574 4246907 4250406 4250409 4251072 4256818 4259989 4259994 4260650 4263826 4264477 4269574 4269581 4270225 4273413 4273415 4273420 4273560 4274050 4274055 4279175 4279798 4283007 4283010 4283015 4283017 4288770 4293203 4293208 4296434 4296436 4297032 4302189 4302191 4302196 4302780 4306028 4306612 4311779 4312355 4312360 4315611 4315616 4316185 4319448 4325198 4325485 4325760 4329590 4329592 4334778 4334783 4338615 4339170 4342449 4348197 4348745 4352034 4352575 4357782 4367895 4371194 4371727 4375026 4375557 4380774 4381302 4384606 4384608 4385130 4390356 4394193 4398025 4403773 4404285 4407605 4407699 4408112 4413353 4417193 4417690 4421025 4421027 4421519 4426775 4427265 4430612 4430614 4436577 4436842 4440194 4440201 4440672 4445954 4446418 4449786 4449789 4450242 4450245 4453625 4453628 4453698 4454074 4459381 4459388 4459815 4459817 4459820 4463642 4463645 4468970 4468975 4472814 4473215 4476649 4477045 4477047 4482402 4482788 4486234 4486241 4486617 4491989 4492361 4496188 4501571 4501576 4501685 4501933 4505408 4514991 4515032 4515336 4515340 4518823 4519163 4524571 4524648 4524908 4528407 4528465 4528733 4528736 4532239 4532563 4537987 4537995 4537997 4538306 4538308 4541829 4547886 4551414 4551706 4551708 4551711 4551713 4555246 4555248 4555533 4561001 4561008 4564840 4565108 4570591 4570596 4570598 4570849 4570851 4570854 4574437 4574442 4574452 4574459 4574464 4574466 4574471 4574679 4580219 4580221 4584254 4587890 4588074 4588078 4588083 4593645 4593648 4593814 4593817 4597480 4597485 4597487 4597639 4603235 4603240 4603242 4603363 4603365 4603373 4603375 4603378 4603380 4603382 4607074 4607079 4607086 4607091 4607178 4607183 4607185 4607188 4607190 4607193 4610926 4610928 4610933 4610940 4610943 4610950 4610957 4610962 4610967 4610972 4610976 4610979 4610981 4610984 4610986 4610988 4610991 4610993 4610998 4611003 4611005 ];
backgroundInd = [19340 19343 19345 19348 28920 28935 32774 48085 48088 48107 57692 61519 61531 74945 84528 88362 88367 111354 117102 117141 118444 118453 118461 118473 118497 118514 118528 118538 118550 118557 128147 130514 131812 131844 140094 140157 141380 145164 145195 145398 153506 154983 159358 160468 160733 182244 182386 183404 183740 186242 195829 199686 200571 200996 209068 209299 209336 215117 215868 222822 222844 222854 223998 228225 238199 238211 238399 238421 238447 238457 238771 242178 242200 242303 242530 242586 251644 251656 251746 251903 252745 255513 255534 255542 255563 255889 265339 270375 278777 284600 285324 293364 294127 297966 297969 310604 321728 350470 362328 367714 396454 402560 435129 446266 473444 506009 511400 523251 546238 569218 593773 601780 624767 630515 649333 653505 670742 678073 710642 712889 758866 779613 797178 843155 867742 875727 909226 909245 909303 921709 945253 955871 958113 968260 972413 990682 1018474 1023252 1024842 1050076 1066029 1069236 1074007 1078816 1112290 1115220 1125490 1130220 1134380 1144826 1147792 1148562 1148615 1170784 1207188 1214524 1239760 1260508 1272332 1283500 1293080 1304904 1305732 1319904 1327896 1360468 1381218 1427209 1429441 1443462 1453003 1472279 1473205 1475425 1495083 1495408 1507997 1528784 1551783 1559729 1574068 1593095 1605713 1607359 1619536 1630358 1674689 1676352 1689779 1699351 1704470 1705104 1705107 1753245 1782340 1787468 1799232 1809589 1852610 1854796 1855937 1919945 1920273 1923777 1924544 1962099 1994671 1995837 1996288 2017663 2021821 2034907 2050235 2064412 2073227 2086639 2092081 2113463 2132983 2142201 2159445 2184348 2188974 2198937 2203201 2215001 2225433 2225448 2226193 2231145 2231198 2238860 2243741 2257153 2270565 2280145 2281000 2285893 2286668 2308888 2310490 2313475 2322744 2323128 2341460 2342283 2356445 2366032 2366061 2369850 2369852 2369874 2379015 2381698 2383255 2397808 2398633 2411293 2411990 2412048 2420540 2421628 2424531 2433652 2433662 2433664 2437262 2437475 2437511 2438372 2438807 2447588 2448452 2452791 2454207 2460517 2460853 2466188 2466719 2467537 2476642 2477197 2477201 2479701 2490529 2492990 2493118 2493500 2493763 2493818 2494443 2506868 2507857 2517348 2523188 2523193 2531151 2532773 2535304 2536607 2546086 2550026 2561928 2563443 2571727 2578776 2592063 2592183 2601770 2613638 2615185 2617733 2619017 2627043 2634205 2634347 2642011 2647759 2661022 2669122 2669475 2673008 2674431 2674581 2684009 2689043 2689050 2689069 2689098 2689120 2689137 2689158 2689183 2689197 2689754 2696888 2697409 2702430 2702655 2702672 2702703 2702725 2702759 2702768 2703147 2711315 2711989 2712722 2715485 2715748 2715763 2715772 2715794 2716197 2725314 2725806 2729662 2729911 2729933 2730147 2738711 2739283 2739293 2744360 2745067 2745116 2745154 2745183 2745210 2751520 2751539 2757850 2766853 2768477 2771247 2784102 2790398 2797514 2813385 2816671 2817094 2830527 2839663 2847038 2863111 2895705 2909129 2916019 2918724 2952430 2960767 2985004 3016309 3017576 3039297 3063570 3081444 3109561 3114016 3140842 3150425 3154257 3163837 3169585 3170873 3192577 3216852 3223228 3249422 3271116 3288350 3297925 3311332 3327978 3340065 3376455 3409019 3419941 3464566 3479327 3483722 3511899 3529698 3540632 3566098 3580868 3594835 3635066 3642180 3663806 3669004 3701574 3713622 3724566 3747558 3751942 3766718 3793542 3797931 3799290 3812702 3826114 3830506 3835694 3849103 3870749 3877839 3899494 3900826 3923810 3932068 3946802 3960210 3978059 3996611 4024046 4037458 4044502 4070032 4080901 4098772 4103890 4116016 4130707 4135179 4154339 4167753 4169017 4182425 4192002 4194582 4209239 4223331 4236746 4237972 4259743 4260959 4278905 4283944 4296156 4315321 4316506 4324904 4328738 4334491 4339493 4347905 4352898 4357490 4358644 4367072 4368224 4374749 4375880 4381628 4385455 4391201 4393923 4397765 4404608 4407364 4413122 4414181 4426546 4431420 4436135 4439970 4445723 4445727 4446741 4453396 4459149 4460148 4462983 4468731 4472566 4476403 4485985 4486960 4505152 4506113 4514737 4515688 4518572 4524324 4525258 4528159 4528164 4531998 4537748 4541580 4541585 4547336 4548238 4555000 4560750 4560755 4564592 4565470 4574177 4579925 4587598 4588443 4593346 4597183 4597186 4602934 4603754 4606770 4611411 4616350 4616355 4617154 4620190 4620194 4625942 4625950 4625957 4625959 4625964 4625967 4629799 4630561 4633635 4634379 4634383 4639391 4643225 4643951 4652810 4653519 4658558 4658565 4662399 4666236 4666239 4671992 4675824 4675826 4675831 4676502 4681581 4686060 4689250 4689885 4694998 4695000 4698832 4704580 4708417 4714165 4717997 4718000 4718603 4727580 4727585 4737167 4741568 4744836 4744838 4744843 4744845 4744850 4750598 4751132 4754430 4760697 4767852 4768347 4768354 4773607 4774085 4783655 4793221 4796614 4806198 4810038 4810445 4819620 4819625 4819632 4820013 4823471 4829222 4833059 4833413 4838816 4839154 4842656 4842660 4846500 4846507 4852262 4852264 4852269 4852547 4852552 4856101 4856109 4861857 4862110 4865696 4865703 4865710 4865717 4865720 4865932 4871473 4871480 4871666 4871668 4871673 4875322 4875481 4875486 4875493 4875495 4879308 4879310 4879313 4884909 4884919 4884926 4884931 4884933 4884938 4884943 4884947 4884955 4884960 4884962 4884967 4884969 4884976 4884981 4884986 4884988 4884998 4885005 4885015 4885017 4885020 4885025 4885032 4885034 4885039 4885044 4885049 4885051 4885054 4885056 ];
L = superpixels(X,24625,'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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)