Image processing and analysis, layers on image

15 views (last 30 days)
I am building an image for analysis on matlab that has a bunch of different layers that i have been overlapping using the image() function, but when i go to export the image using saveas() the resolution is the same as the preview window and not good for analysis. is there a way to build the image layers and export it in the native resolution of the layers?

Accepted Answer

DGM
DGM on 27 Mar 2022
It depends what exactly you're doing with image(). If you want to compose an image from many similarly-sized images, you should be able to do that without having to rely on trying to capture the figure contents and all the problems that entails.
If you're just composing the layers by setting the 'AlphaData' property of the image objects, then you can do that by multiplication
BG = imread('peppers.png');
FG = fliplr(BG);
alph = 0.5;
R = FG.*alph + BG.*(1-alph);
imshow(R)
If your images are not the same size, then the composition becomes more complicated. You might have to elaborate on what exactly you're doing.
  2 Comments
Xymbu
Xymbu on 27 Mar 2022
All the images are the same 2000x2000 pixels they have alpha data and then i overlay them. The problem comes when I output the file. It looks like the resolution has been greatly reduced.
DGM
DGM on 27 Mar 2022
Edited: DGM on 27 Mar 2022
Capturing things from figures is tantamount to taking a screenshot. For image processing, consider figures as visualization tools, not as composition tools. Other people may feel otherwise, but that's my perspective.
As I said, I would compose the image by itself. You could use a rudimentary approach like that described above. That would be simple enough if your alpha is scalar. Just work from the bottom image up.
You could do other things depending on what you're dealing with. If your images have full (2000x2000) alpha as a separate array, you could still do the same, or you could use something like MIMT replacepixels(), which just makes the process neater and less dependent on numeric class.
% create some images
BG = imread('peppers.png');
FG1 = imtweak(BG,'lchuv',[1 1 0.25]); % imtweak is also MIMT-only
FG2 = imtweak(BG,'lchuv',[1 1 0.50]);
FG3 = imtweak(BG,'lchuv',[1 1 0.75]);
% some alpha
a1 = imread('pgrad1.png');
a2 = imread('pgrad2.png');
a3 = imread('pgrad3.png');
% compose the images
outpict = replacepixels(FG1,BG,a1);
outpict = replacepixels(FG2,outpict,a2);
outpict = replacepixels(FG3,outpict,a3);
imshow(outpict)
In this example, the layers are ordered BG, FG1, FG2, FG3, with BG on the bottom and FG3 on the top. The composition follows from the base layer and works up to the top.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 27 Mar 2022
@DGM is correct. Deal with the actual images, not screen captures. You can get alpha transparencies by adding in a fraction of the overlay image. You can also add in many other images just make sure you convert to double or else if they're uint8, they will clip at 255. So convert to double, add up all the various weighted images, and then call uint8(rescale(rgbImage, 0, 255)) to make it back into a uint8 RGB image.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!