How to stretch image horizontally and save it
9 views (last 30 days)
Show older comments
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]);
0 Comments
Accepted Answer
Image Analyst
on 3 Jul 2017
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);
More Answers (0)
See Also
Categories
Find more on Explore and Edit Images with Image Viewer App in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!