Fusionar dos imágenes con diferentes canales (R, G, B) usando C # o MATLAB

How to merge ( overlay ) two same images with different effects into one image. I have one image like natural.jpg , I added some effects into that natural.jpg image Now I want to merge that two same image into one image like OutNatural.jpg image.

How can I achieve this in C# language or Matlab.. if any other way then reply me..

Muchas Gracias

preguntado el 09 de enero de 11 a las 09:01

Can you upload the original and edited natural.jpg? Also, can you explain what you mean by different effects? It would be good if you could also provide an image of what you expect the result to look like, by using image editing tools e.g. GIMP. -

2 Respuestas

Mathematically, you can get the desired result by averaging the two images. If you want to emphasize one image or the other, you can use a weighted average. In MATLAB:

function imgC = AverageImages(imgA, imgB, weight)
%# AverageImages - average two input images according to a specified weight.
%# The two input images must be of the same size and data type.

    if weight < 0 || weight > 1
        error('Weight out of range.')
    end
    c = class(imgA);
    if strcmp(c, class(imgB)) != 1
        error('Images should be of the same datatype.')
    end

    %# Use double matrices for averaging so we don't lose a bit
    x = double(imgA);
    y = double(imgB);
    z = weight*x + (1-weight)*y;

    imgC = cast(z, c); %# return the same datatype as the input images

The actual averaging takes place in the line z = weight*x + (1-weight)*y; Si especifica weight = 0.5, the output image will be an equal mix of the two inputs. If you specify 0.9, the output will be 90% imgA y 10% imgB.

The reason for casting the input images to a double data type is because images are usually uint8, which is limited to 0..255. The simple math here should not run into any problems with this data type, but it's a good habit to do your math in floating-point and then cast back to the image's desired data type.

For aesthetic reasons, you might want to average different areas of the images with different weights. You can extend the function to accept either a scalar or a 2D matrix for weight. In the latter case, you just multiply each pixel by the corresponding entry in the weight matriz.

Respondido el 09 de enero de 11 a las 13:01

or you could just use IMADD/IMLINCOMB from the Image Processing Toolbox - Amro

@Amro - Octave doesn't have those functions, but yes, that's definitely the easier way to go. Make it an answer! - mtrw

Thanks @mtrw I trying as you mentioned here. I also know something about matlab. b'coz I have master degree in mathematics - Abhishek B.

From the computer...deep deep inside the computer ;) - mtrw

huhhhh. you are one of the windows service.. running everyday... good job. ha ha ha dont mind... - Abhishek B.

Como se muestra @mtrw, one way to merge the images is using a linear combination of the two. The Image Processing Toolbox for MATLAB provide two functions for this purpose, namely IMADD y IMLINCOMB (Unfortunately the Image package for Octave have no similar functions, though they are not hard to implement by yourself).

One advantage of MATLAB's implementation is that on Intel architecture processors, they use the IPP library to speed up execution.

contestado el 23 de mayo de 17 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.