Matrix padding with zeros

2 views (last 30 days)
Darek Myszk
Darek Myszk on 29 Apr 2020
Answered: Geoff Hayes on 29 Apr 2020
Hello. I have a problem with my program. I make encryption by image. I based on 16-bit blocks. When I load picture (e.g. 16x16 / 128x128 / 256x256) and make my transformation on this everythink is ok. The problem occurs when the image has different dimensions (e.g. 50x50). In this case I have a size matrix: 50x50x3 (rgb). I have to extend each sub matrix to 64 (modulo 16, rounding up to a full multiple of 16) by add '255' so that finally the combination of three '255' gives white. Any ideas?

Answers (1)

Geoff Hayes
Geoff Hayes on 29 Apr 2020
Darek - perhaps create the 64x64x3 matrix with all elements set to 255 and then replace a subset of that matrix with the 50x50x3.
myImage = uint8(randi(255,50,50,3));
myPaddedImage = uint8(255*ones(64,64,3));
myPaddedImage(1:50,1:50,:) = myImage;

Community Treasure Hunt

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

Start Hunting!