How to stretch image horizontally and save it

11 次查看(过去 30 天)
Hi, how to stretch an image horizontally and to save the image. I did found the code on the website but i couldnot able to do it. I am having difficulty using the code
% code Img=imread('b1.tiff');
[rows columns numberOfColorChannels] = size(Img);
subplot(2, 1, 1);
imshow(Img);
newWidth = [1 0.592013 * columns];
subplot(2, 1, 2);
imshow(Img, 'XData', newWidth);
stretchedImage = imresize(Img, [rows newWidth]);
But i couldnot able to save the image. It gives an error of
Error using coder.internal.errorIf (line 8)
Function IMRESIZE expected input number 2, MAP, to be a valid colormap. Valid colormaps cannot have values outside the range [0,1].
Error in iptcheckmap (line 47) coder.internal.errorIf(true, 'images:validate:badMapValues', ...
Error in imresize>parsePreMethodArgs (line 343) iptcheckmap(map, mfilename, 'MAP', 2);
Error in imresize>parseInputs (line 248) [params.A, params.map, params.scale, params.output_size] = ...
Error in imresize (line 141) params = parseInputs(varargin{:});
Error in rescale (line 8) stretchedImage = imresize(Img, [rows newWidth]);

采纳的回答

Image Analyst
Image Analyst 2017-7-3
newWidth needs to be a single integer, not a 1-by-2 array of floating point numbers. This works:
Img=imread('cameraman.tif');
[rows, columns, numberOfColorChannels] = size(Img);
subplot(2, 1, 1);
imshow(Img);
newWidth = round(0.592013 * columns)
subplot(2, 1, 2);
stretchedImage = imresize(Img, [rows newWidth]);
imshow(stretchedImage);

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by