How do i combine a set of images on MATLAB?

2 ビュー (過去 30 日間)
Mohammed
Mohammed 2016 年 9 月 4 日
コメント済み: Walter Roberson 2016 年 9 月 5 日
I am trying to write a function that Combines coloured images into a single RGB image(the images are the inputs which are entered as a 1D cell array). the function should return a 3D array representing the combined image.we know that for example that the blue intensity value for the pixel in row 1, column 1 of the combined image will be the sum of the blue intensity values of each pixel in row 1, column 1 of the input images. how do i write a function to represent this?
Thanks
  4 件のコメント
Image Analyst
Image Analyst 2016 年 9 月 5 日
Are you sure you want the sum and not the average? Do you want the combined image to be like all images are averaged together, which is like you superimposed them all? Because if you sum uint8 images eventually they will clip at 255. If you cast to double and sum and then divide by the number of images, then cast to uint8 you will not have clipping and the images will look like the combined (averaged/superimposed) image.
Mohammed
Mohammed 2016 年 9 月 5 日
Thanks for the response
i am not sure which will be the correct word to describe the situation? sum or average? but i want the output image to be a mixture of the images entered.

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 9 月 5 日
total_image = sum( cat(4, TheCell{:}), 4, 'native');
  5 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 5 日
The 'native' means that the sum should be carried out in whatever data class that the data itself is. Without the 'native' the default is to use double precision.
It is the difference between
uint8(254) + uint8(2)
and
double(254) + double(2)
The first of those will be carried out in uint8 arithmetic resulting in uint8(255) because uint8() "saturates" if you add enough values together. On the other hand, displaying uint8(255) as an image will know that is just the brightest intensity on a scale of 0 to 255.
The second of the two would result in double(257) . Displaying double(257) would result in the brightest intensity but for a very different reason: the expected range for double is 0 to 1 and everything from 1 upward would display as maximum intensity.
So you need to be considering two things: 1) What do you want to have happen when enough values get added together that 255 would be reached; and 2) the need to be able to display the image afterwards.
Walter Roberson
Walter Roberson 2016 年 9 月 5 日
If you want the average image, then
total_image = cast( mean( cat(4, TheCell{:}), 4), class(TheCell{1,1}) );

サインインしてコメントする。


Image Analyst
Image Analyst 2016 年 9 月 5 日
See my attached demo to average RGB images together.

Community Treasure Hunt

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

Start Hunting!

Translated by