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 9152791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:08:27+00:00 2026-06-17T12:08:27+00:00

I am new to Matlab and to Image Processing as well. I am working

  • 0

I am new to Matlab and to Image Processing as well. I am working on separating background and foreground in images like this

passport image blue background

I have hundreds of images like this, found here. By trial and error I found out a threshold (in RGB space): the red layer is always less than 150 and the green and blue layers are greater than 150 where the background is.

so if my RGB image is I and my r,g and b layers are

redMatrix = I(:,:,1);
greenMatrix = I(:,:,2);
blueMatrix = I(:,:,3);

by finding coordinates where in red, green and blue the values are greater or less than 150 I can get the coordinates of the background like

[r1 c1] = find(redMatrix < 150);
[r2 c2] = find(greenMatrix > 150);
[r3 c3] = find(blueMatrix > 150);

now I get coordinates of thousands of pixels in r1,c1,r2,c2,r3 and c3.

My questions:

  1. How to find common values, like the coordinates of the pixels where red is less than 150 and green and blue are greater than 150?
    I have to iterate every coordinate of r1 and c1 and check if they occur in r2 c2 and r3 c3 to check it is a common point. but that would be very expensive.
    Can this be achieved without a loop ?

  2. If somehow I came up with common points like [commonR commonC] and commonR and commonC are both of order 5000 X 1, so to access this background pixel of Image I, I have to access first commonR then commonC and then access image I like

    I(commonR(i,1),commonC(i,1))

that is expensive too. So again my question is can this be done without loop.

Any help would be appreciated.

I got solution with @Science_Fiction answer’s

Just elaborating his/her answer

I used

mask = I(:,:,1) < 150 & I(:,:,2) > 150 & I(:,:,3) > 150;
  • 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-06-17T12:08:28+00:00Added an answer on June 17, 2026 at 12:08 pm

    Your approach seems basic but decent. Since for this particular image the background is composed of mainly blue so you be crude and do:

    mask = img(:,:,3) > 150;
    

    This will set those pixels which evaluate to true for > 150 to 0 and false to 1. You will have a black and white image though.

    imshow(mask);
    

    To add colour back

    mask3d(:,:,1) = mask; 
    mask3d(:,:,2) = mask; 
    mask3d(:,:,3) = mask;
    
    img(mask3d) = 255;
    imshow(img);
    

    Should give you the colour image of face hopefully, with a pure white background. All this requires some trial and error.

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

Sidebar

Related Questions

I am very new to matlab and image processing toolbox. I have a source
I am new in Matlab, I Have 3 equation like this: -5*x + y
I am new to image processing and matlab. I am trying to extract the
If I have an image like this I want to break the image according
Apologies if this is a stupid question, I'm relatively new to Matlab. I've got
I am new to MatLab. I am trying to do some work on image
I am new in MATLAB, I am trying to implement flood filling using this
I am not new to Matlab, but I have a very strange error I
I have an intensity/greyscale image, and I have chosen a pixel inside this image.
I have a simple code to show an image in Matlab. I use imread()

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.