Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6942109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:58:22+00:00 2026-05-27T12:58:22+00:00

My question has two parts. First one is: How can I include the background

  • 0

My question has two parts. First one is:

How can I include the background as a component in the bwconncomp function, because it’s default behavior doesn’t include it.

Also, and this is my other question is, how can I select the n-th largest component based on what I get by using bwconncomp.

Currently I was thinking about something like this, but that doesn’t work 😛

function out = getComponent(im,n)
CC = bwconncomp(im,4);
%image is an binary image here

numPixels = cellfun(@numel,CC.PixelIdxList);
sortedPixels = sort(numPixels,'descend');
w = sortedPixels(n);
[largest, index] = find(numPixels==w);
im(CC.PixelIdxList{index}) = 0;
out = im;

But that doesn’t work at all. But im not too sure what the CC.PixelIdxList{index} does, is it just changing elements in the array. I also find it kinda vague what exactly PixelIdxList is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:58:22+00:00Added an answer on May 27, 2026 at 12:58 pm
    1. To find the background, you can use ‘not’ operation on the image
    2. ‘PixelIdxList’ is not what you need. You need the ‘Area’ property.

    function FindBackgroundAndLargestBlob
    x = imread(‘peppers.png’);
    I = x(:,:,2);
    level = graythresh(I);
    bw = im2bw(I,level);
    b = bwlabel(bw,8);
    rp = regionprops(b,’Area’,’PixelIdxList’);
    areas = [rp.Area];
    [unused,indexOfMax] = max(areas);
    disp(indexOfMax);
    end

    Update:
    You can do it with bwconncomp as well:

    function FindBackgroundAndLargestBlob
    x = imread(‘peppers.png’);
    I = x(:,:,2);
    level = graythresh(I);
    bw = im2bw(I,level);
    c = bwconncomp(bw,4);
    numOfPixels = cellfun(@numel,c.PixelIdxList);
    [unused,indexOfMax] = max(numOfPixels);
    figure;imshow(bw);
    bw( c.PixelIdxList{indexOfMax} ) = 0;
    figure;imshow(bw);
    end

    Which will give the following results:
    Before
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question has two parts, one of which I already have the answer for.
This question actually has two parts. The first part: I've been developing my first
This question has two parts. First, I need to isolate two strings of text
This question has two parts: #1 I have a functions.php that is filled with
The question is in two parts. The first is conceptual. The next looks at
This is a two part question, but first some background information: I have a
This question has been discussed in two blog posts ( http://dow.ngra.de/2008/10/27/when-systemcurrenttimemillis-is-too-slow/ , http://dow.ngra.de/2008/10/28/what-do-we-really-know-about-non-blocking-concurrency-in-java/ ),
This question has spawned out of this one. Working with lists of structs in
I am working on a scientific application that has readily separable parts that can
I have a page that has two parts that are slower loading. As they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.