Add pad array for image only to top and bottom

16 ビュー (過去 30 日間)
Malan Jayanka
Malan Jayanka 2016 年 10 月 2 日
コメント済み: Malan Jayanka 2016 年 10 月 2 日
I want to add pad array to a given image, for top and bottom sides only. How can I do this
**I don't want black outline it is only for illustration
I have used this code but it appears in only left and right sides only
rgbImage = imread('image path');
[heigth,width,dim] = size(rgbImage);
if heigth>width
cal=(heigth-width)/2;
calculatedWidth=double(fix(cal));
paddedImage = padarray(rgbImage,[0 calculatedWidth],255);
else
cal=(width-heigth)/2;
calculatedHeigth=double(fix(cal));
paddedImage = padarray(rgbImage,[0 calculatedHeigth],255);
end
imshow(paddedImage);
*output image that I have got

採用された回答

Guillaume
Guillaume 2016 年 10 月 2 日
Isn't the problem obvious if you read the documentation of padarray?
The first element of the 2nd argument of padarray is the padding top and bottom, the 2nd element is the padding left and right. You always specify 0 even when you want to add top and bottom.
Replace the second padarray call by:
paddedImage = padarray(rgbImage,[calculatedHeigth 0],255); %swapped the elements of padsize
  1 件のコメント
Malan Jayanka
Malan Jayanka 2016 年 10 月 2 日
Thank you Guillaume, Yes it worked. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by