user3313281
user3313281

Reputation: 5

Save image in actual size in matlab

I want to save color image in original size (here is 146 by 220 pixel), but by this method the image will be saved in 1200 by 897 including extra marging. Actually the image will be save in larger size. I want to save it exactly in 146 by 220 pixel. Because i want to compare its pixels one by one with original image's. If i gain extra pixel comparing activity will be problematic for me. Thank you in advance for your attention.

function   []=doCmeans (imInput)
        H = single(imInput(:));% original image is gray scale
        nRegions = 5;
        options = [2 100 1e-5 0];
        [Center, U, obj_fun] = fcm (H,nRegions,options);
        maxU = max(U);
        for i = 1:nRegions
        tmpindex = find (U(i,1))==maxU;
        H (tmpindex)= i;
        end
        [r c]=size (imInput);
        imFClass = reshape (H, r,c);
        colormap(hsv(5));
        h = figure('visible', 'off'); imshow(imFClass,[]);
        print(h,'-djpeg',sprintf('ImFuzzy.jpg'));
end

Upvotes: 0

Views: 660

Answers (2)

cifz
cifz

Reputation: 1078

The answer from Daniel is correct and is how you should do it, but if you still really need to save the image from the figure you have to do a couple of extra steps.

First you want to make sure that the figure has the exact same size of the image you're showing and then you want to get the content of the figure.

To do so, just give to imshow the arguments 'Border','tight'.

h = figure('visible', 'off'); imshow(imFClass,[], 'Border','tight');

Then you obtain and save the colour data from the frame as follow

myPic = getframe(h);
imwrite(myPic.cdata, 'yourPathName','yourFormat')

And this should do the trick.

However this is obviously useless if you just need to save the image and not really the content of a figure.

Upvotes: 1

Daniel
Daniel

Reputation: 36710

print saves the object you are passing, in this case a figure and not an image. The figure has probably a larger size. Use imwrite instead, and don't forget to pass the map.

Upvotes: 1

Related Questions