Emulate gimp screen effect in rgb image
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello world. I would like to do something like gimp's screen effect. The documentation is here. Basically is like emulating the alpha where something is black and for the other colors multiply by the color of the other layer. So I have and image I and a mask M, the image I is a grayscale image and M is one color. They are both the same size. and I want to do the following operation between them:
E= 255 - ((255-M)*(255-I))/255
I tried writing it like that in matlab and it didn't work, any ideas?
1 comentario
Respuestas (3)
Kushagr Gupta
el 19 de Dic. de 2016
Provided that both matrices I and M are of the same size and assuming that element by element operation is being asked for, it can be done by using the dot notation operator.
Whenever, element by element multiplication or division or other mathematical operation needs to be performed in MATLAB, the math operator can be prefixed by a dot and it makes the operation to be performed per element basis.
For this particular equation it would look like:
E= 255 - ((255-M).*(255-I))/255
0 comentarios
DGM
el 22 de Mayo de 2021
Editada: DGM
el 22 de Mayo de 2021
I know this is old, but I'm bored and browsing, so I'll leave answers that interest me where they may help the next person.
This problem is almost certainly being caused by one of two things:
- As Kushagr noted, using matrix multiplication instead of elementwise multiplication
- and/or not using the right numeric class
- or not ensuring that intermediate calculations don't cause data truncation in an integer class
If you don't want to bother writing image blending and alpha compositing routines, imblend() already has you covered:
That includes essentially every blend mode under the sun, and specifically offers compatibility with GIMP's ... unique compositing behavior (and others). If you want a graphical interface for layered image composition, just get the parent toolbox, which includes both imblend() and the GUI imcompose()
EDIT: I might as well add an example (some of these tools are also from MIMT):
[inpict map] = imread('canoe.tif');
% inpict is RGB double
inpict = ind2rgb(inpict,map);
% gradpict is uint8, with only one channel
gradpict = lingrad(imsize(inpict,2),[0 1; 1 0],[0; 1]*255,'cosine','uint8');
% but imblend will blend them anyway
A = imblend(gradpict,inpict,1,'screen');
B = imblend(gradpict,inpict,1,'addition');
C = imblend(gradpict,inpict,1,'foglighten');
D = imblend(gradpict,inpict,1,'lightenrgb');
E = imblend(gradpict,inpict,1,'lighteny');
% most modes are parametric and can be adjusted
F = imblend(gradpict,inpict,1,'malekidodge',0.9);
blendpict = cat(2,cat(1,A,B,C),cat(1,D,E,F));
This demonstrates 'screen' and some other similar lightening modes.
If you don't like my tools, there are also some other submissions on the FEX which handle common modes like 'screen'. If you still want to roll your own tools, you can always just use imblend() or other existing implementations as working examples to help understand what's going on.
0 comentarios
Ver también
Categorías
Más información sobre Computer Vision with Simulink en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!