Clear Filters
Clear Filters

How can I add custom pixel values in a 4th layer matrix of an RGB image?

1 view (last 30 days)
Hi I am quite new to matlab so excuse my amateur way of expressing the problem. Let's say I have truecolor "initial_image" MxNx3 and I want to create a "4d_image" identical to the "initial_image" which will be a MxNx4 or just a new matrix MxN which will descrive the initial_image objects in a pixel level.
First, I want to be able to manually choose a pixel region in the "4d_image" and then for that certain region I want to manually add a new value to each pixel (without any computer vision or image processing algorithm). For example all the pixels of the "4d_image" which are in the rectangle [46:100 3456:3890] that I manually chose are of type "door" (that ofc will correspond to a numeric value let's say from 0 to 255 so that it won't be a string).
So the output image would be an MxNx4 image in which the 4th layer matrix will have the information about the different objects included in the image in a pixel level. Or it will be a new 2-D matrix Q(M,N) that will describe each pixel of the initial image in the right i,j position.
Do you have any advice on how to start? I already checked some functions like "imfreehand", "impixel", "impixelinfo", etc but I am getting lost on how to extract those features and use them to create the 4th matrix and thus the 4d_image. What subjects or kewords should I look for?
  8 Comments
Guillaume
Guillaume on 10 Oct 2018
But I specifically want those labels in their right (i,j) position which will correspond to the same (i,j) position of the input image. I don't know is this similar to a color map?
This is exactly the description of a labeling matrix and is commonly used in image processing. Matlab has several functions to work and generate labeling matrices, see for example label2rgb. It is not a colour map.
_ Is there a way to interact with the image and do that process manually?_
Note that you want two different things: a) segment the image in different blobs. b) label the blobs.
For the segmentation it would be better would be to come up with a way to do it automatically. In any case, the segmentation link I gave earlier gives plenty of methods to segment the image. The second link on that page points to the Image Segmenter App which lets you manually select regions.
Orfeas Skentzos
Orfeas Skentzos on 10 Oct 2018
Edited: Orfeas Skentzos on 10 Oct 2018
Thank you Guillaume. That's really helpful! I will check the links.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 10 Oct 2018
You can add another plane to your 3 plane RGB image like this:
image3d = cat(rgbImage, image2d);
Note: adding a 4th plane does not make the image a 4-D image like you hinted - it's still a 3-D image just with 4 channels/slices/planes.
  2 Comments
Orfeas Skentzos
Orfeas Skentzos on 10 Oct 2018
Yeah maybe the naming of the new image output was misleading. Thanks for the tip. I will give it a try. But first I have to figure out how I will manually do the labeling so then I can insert this information to the new plane as you indicated.
Guillaume
Guillaume on 10 Oct 2018
Edited: Guillaume on 10 Oct 2018
As commented in the question, it is much easier to keep the label matrix separate from the image matrix as matlab image processing functions won't understand what that fourth plane represent.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 10 Oct 2018
See my classification demo where you can draw regions. You could then use those regions to build up a labeled image, instead of doing color segmentation like the demo does.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!