Wednesday 15 April 2015

Resize an image along rows only or columns only in matlab -



Resize an image along rows only or columns only in matlab -

i'm writing function in matlab zoom or shrink image using bicubic interpolation. however, function resizes image along both rows , columns. if want enlarge image along rows only, or along columns only? code far

function pic_new = zoom_image(pic, zoom_value) actualsize = size(pic); newsize = max(floor(zoom_value.*actualsize(1:2)),1); newx = ((1:newsize(2))-0.5)./zoom_value+0.5; %# new image pixel x coordinates newy = ((1:newsize(1))-0.5)./zoom_value+0.5; oldclass = class(pic); %# original image type pic = double(pic); %# convert image double precision interpolation if numel(actualsize) == 2 pic_new = interp2(pic,newx,newy(:),'cubic'); end pic_new = cast(pic_new,oldclass); end

updated: able resize image both along rows , columns. however, doesn't work right

this original image: https://imagizer.imageshack.us/v2/895x383q90/r/903/4jm76i.png

this image after beingness enlarge 2.5 along rows , shrunk 1.3 along columns: https://imagizer.imageshack.us/v2/323x465q90/r/673/ehiaob.png

why there such black box in result image?

updated 2: how did: in command window type

>> img = imread('pic.pgm'); >> newimage = zoom_image(img, 2.5, 1/1.3); >> imshow(newimage)

try editing function have separate zoom rows , columns, la

function pic_new = zoomfunc(pic, zoom_valuex, zoom_valuey) actualsize = size(pic); newsize = max(floor([zoom_valuey zoom_valuex].*actualsize(1:2)),1); newx = ((1:newsize(2))-0.5)./zoom_valuex+0.5; %# new image pixel x coordinates newy = ((1:newsize(1))-0.5)./zoom_valuey+0.5; oldclass = class(pic); %# original image type pic = double(pic); %# convert image double precision interpolation if numel(actualsize) == 2 pic_new = interp2(pic,newx,newy(:),'cubic'); end pic_new = cast(pic_new,oldclass); end

image matlab resize

No comments:

Post a Comment