In MATLAB, we can reshape a layer of a multi-layered image using the reshape
function. The reshape
function takes in the input layer and new size parameter as input and returns the reshaped layer. Here's an example code snippet:
main.m377 chars17 lines
In the code snippet above, we extract the RED
color layer from the peppers.png
RGB image, get its original size using the size
function, and reshape it to a new size of [512 256]
using the reshape
function. The size of the original and reshaped layer are displayed using the disp
function.
Note that the reshape
function rearranges the values of the layer in a column-wise manner. If the new size specified in the reshape
function does not result in the same number of elements as the original size, MATLAB will throw an error.
gistlibby LogSnag