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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:28:28+00:00 2026-06-11T03:28:28+00:00

I have an RGB image such that: Img[3*(row*imgWidth+column)+0], //R Img[3*(row*imgWidth+column)+1], //G Img[3*(row*imgWidth+column)+2] //B represent

  • 0

I have an RGB image such that:

Img[3*(row*imgWidth+column)+0], //R
Img[3*(row*imgWidth+column)+1], //G
Img[3*(row*imgWidth+column)+2]  //B

represent the intensity value for each pixel for each RGB. What is a clean method to pad borders of 0’s(0-255 scale) around the image? The border can be adjusted to any width.

The only thing I can come up with is pretty much manual insertion of rows and columns, which becomes a very tediously long piece of code.

sorry, but libraries are not what I’m looking for here

  • 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-11T03:28:30+00:00Added an answer on June 11, 2026 at 3:28 am

    Here’s the most readable way I can think of, which is also reasonably efficient. Say you have an image of dimensions Width by Height and desired margins of Left, Right, Top, and Bottom. Allocate a buffer of Width + Left + Right by Height + Top + Bottom filled with zeros. In C++ you can use one of the handy std::vector constructors:

    const auto Channels = 3;
    
    const auto TargetWidth = Width + Left + Right;
    const auto TargetHeight = Height + Top + Bottom;
    
    std::vector<uint8_t> target(TargetWidth * TargetHeight * Channels);
    

    The C function calloc() is also an option. Next, copy each row in the source image to the target image, starting at vertical offset Top and horizontal offset Left. Use std::copy() to copy rows, and run the outer loop in row-major order to avoid cache misses:

    for (int y = 0; y < Height; ++y) {
        const auto* const source_row = &source[y * Width * Channels];
        auto* const target_row = &target[(y + Top) * TargetWidth * Channels + Left];
        std::copy(source_row, source_row + Width * Channels, target_row);
    }
    

    If you can use 32-bit RGB0 or RGBA instead of 24-bit RGB, you might see faster copying thanks to more consistent alignment, for which std::copy() or memcpy() are well optimised. If you can use OpenMP, you might also experiment with parallelising the loop:

    #pragma omp parallel for
    for (int y = 0; y < Height; ++y) {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using OpenCV. I have an RGB image, each value is a float. I also
I have an array of integers which represent a RGB image and would like
I have an RGB image, call it img , represented as a double array
Imagine you have an RGB image and want to process every pixel: import numpy
I have an RGB image in MATLAB, and I want to loop through each
I have a greyscale image which was created from a RGB image using farmula:
Or say does 1 denotes white for an RGB image? I have this question
I have a raw image buffer in the RGB format. I need to draw
I have a table with an image inside: <table style=border: 3px solid rgb(0, 0,
You have 2000 raw images, 52x52 pixels, RGB 24 bits, that correspond to the

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.