How to increase maximum figure size?
20 views (last 30 days)
Show older comments
Hi everyone, I use MATLAB for image processing. After having done my calculations I would like to save the image. Since the image resolution is higher than my screen resolution I encouter problems while displaying or saving my image.
myimage=rand(600,1800);
figure();
imagesc(myimage);
axis tight;
set(gca, 'Visible', 'off');
set(gca, 'Position', [0 0 1 1]);
set(gcf, 'Position', [1 1 size(myimage, 1) size(myimage, 2)]);
pause(2);
get(gcf,'position')
The height seems to be limited by my screen resolution: 1920x1200. How can I increase the window size so that it fits my actual image size?
Thank you
3 Comments
Adam
on 7 Sep 2016
Assuming your image is a 2d indexed image you can map it via the colourmap to produce a true RGB image for saving. I'll put that in an answer below.
Accepted Answer
Adam
on 7 Sep 2016
Edited: Adam
on 7 Sep 2016
myImage=rand(600,1800);
cmap = flipud( jet(256) );
myImageIndices = uint8( myImage * 255 ) + 1 % Note - this is because the colourmap by default is size 256. If you change the colourmap size then use int16 and change 255
rData = reshape( cmap( myImageIndices, 1 ), 600, 1800 );
gData = reshape( cmap( myImageIndices, 2 ), 600, 1800 );
bData = reshape( cmap( myImageIndices, 3 ), 600, 1800 );
rgbData = cat(3, rData, gData, bData );
imwrite( rgbData, 'myimage.png' )
That should map your data onto a colourmap and then save it. Obviously if I was doing this properly I would put it in a function (which I have done for my own usage) and not hard code the image sizes, etc, but you can change those as you see fit. You can also choose the size of colourmap you use if you don't want 256, but if you go higher then use a uint16 or int16 to store the image indices into the colourmap.
There may be quicker ways using builtin image processing toolbox functions, but I have never familiarised myself with those so have tended to write my own classes or functions to do this type of thing.
To deal with different caxis limits you would want to change this line:
myImageIndices = uint8( myImage * 255 ) + 1;
The 255 in here means it is mapping to the full range of the colourmap. If you change this number then your data will map to different values in the colourmap. e.g. if you changed it to 511 then you should get the equivalent of a [0 0.5] clims. This will work as is in the above case because the uint8 will clip. If you are using a smaller colourmap or a uint16 then you will need to manually clip the indices down to the maximimum range of the colourmap. Again there may be easier ways to do this. I have a class that does range mapping for me so it is just a one line call to map from any input range to any output range.
More Answers (0)
See Also
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!