Hi,
Why I can not merge these two images?
I = imread('peppers.png');
[height, width] = size(I);
blankImage = ones(height/5,width,3);
combineImg = [I; blankImage]
imshow(combineImg);
Thanks

 採用された回答

Ben11
Ben11 2014 年 10 月 15 日
編集済み: Ben11 2014 年 10 月 15 日

1 投票

This will work:
clc
clear
close all
I = imread('peppers.png');
[height, width,Channels] = size(I)
blankImage = ones(round(height/5),width,Channels,'like',I);
combineImg = [I; 255*blankImage];
imshow(combineImg);
First you needed to round the height dimension, and then since the image is RGB it has 3 channels, so the 3rd output of 'size' is 3, hence you had a conflict when trying to concatenate.
Here is what I got as output. Notice that there is a white image at the bottom but it does not show up well here. Try it in Matlab and it will work.
EDIT: Here is what it look like with a black blankImage.To get it, change
combineImg = [I; 255*blankImage];
with
combineImg = [I;blankImage];
Output:

4 件のコメント

hu
hu 2014 年 10 月 15 日
I use 2012a version and I got these errors:
Error using ones
Leading inputs must be numeric.
Error in Untitled2 (line 8)
blankImage = ones(round(height/5),width,Channels,'like',I);
Any reason why?
Ben11
Ben11 2014 年 10 月 15 日
mhh nope! I'm using 2014a; maybe in 2012 you can't use 'like' to cast the image as the same type as the original. What if you use this:
blankImage = ones(round(height/5),width,Channels,'uint8');
hu
hu 2014 年 10 月 15 日
Thanks, it working
Ben11
Ben11 2014 年 10 月 15 日
ok great then!

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

その他の回答 (1 件)

Karbala'a Unvi. Science
Karbala'a Unvi. Science 2014 年 11 月 21 日

0 投票

hi every one I have a cropped image from the original image. The cropped one is processed. Now I want to reteren that part to the original image.. the processing on the cropped image is not to much, it will not change so many things in the cropped image. Need for the help as fast as you can

タグ

質問済み:

hu
2014 年 10 月 15 日

回答済み:

2014 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by