简体   繁体   中英

Why this imagesc-imshow with Colormap not Working in Matlab?

I am considering and expanding the slider here in the answer about To show/join Two Images Simultaneously in Matlab's slider with the capability of changing the colormap by using .mat data in Matlab 2016a. Therefore, I have to use imagesc because there you can alter the colormap. I want to make the images from .mat data containing the variables time , potential and matrix such that I can change colormap/etc

Code with 1 imagesc-imshow

for k=1:2
   % loaded variables from .mat data
   img=imagesc(time, potential, matrix); 
   colormap('jet')
   signal=cat(2,signal,img);
end

windowWidth = 320;
hImg = imshow(signal(:,1:1 + windowWidth,:), ... % TODO complication here?
    'InitialMagnification', 100, 'Border', 'tight');

% End of the video code here https://stackoverflow.com/a/35924614/54964
% Not necessary for the case here!

At the end, I want to do the magnification with imshow . Output

Index exceeds matrix dimensions.

Error in masi (line 7)
hImg = imshow(signal(:,1:1 + windowWidth,:), ...

Code 2 with imagesc-write-imshow

I could not find a way to do imagesc-imshow without writing to the disc as .png and reading .png image result. So there are only the saveas and imread here

for k=1:2
   % loaded variables from .mat data
   imagesc(time, potential, matrix); 
   colormap('jet');

   saveas(gcf,'/tmp/Figure','png');
   imgRGB=imread(fullfile('/tmp/','Figure.png'));

   signal=cat(2,signal,imgRGB);
end

windowWidth = 320;
hImg = imshow(signal(:,1:1 + windowWidth,:), ... 
    'InitialMagnification', 100, 'Border', 'tight');

which gives the correct output by writing and reading.

Experimenting total Resolution with print -RGBImage -rNUMBER, Suever

I am experimenting Suever's answer for total resolution. I find the default image result noisy which you can easily see in slider-video. I think the best resolution is -r95. I know that the signal has indicators with 95% sensitivity so I selected it directly. There are uncertainties about 5-15% in the measurement so -r85 could be also good but I cannot evaluate it right now enough well. Low boundary is r55 for the resolution in my system without generation of the image (OS X 13" Macbook Air). Some resolution values and my experience

Error with >r124 in GUI, which indicates some upper boundary

Struct contents reference from a non-struct array object.

Error in matlab.graphics.internal.getframeWithDecorations (line 49)
x = bi.getWidth();

Error in alternateGetframe

Error in getframe (line 84)
  x = alternateGetframe(parentFig, h, offsetRect, withinClientRect);

Error in masi (line 114)
    writeVideo(vid, getframe());

It would be very nice to be able estimate the quality of resolution between r85, r90 and r95 when uncertainty of the input signal is 5-15% such that I would not lose it in stages from my original 1D signal.

Reviewing Units per Inches and Ghosts, Suever

I got strange results and found that [0 0 15 15] is the best selection with big output image, little ghosts and no boundary artifacts. I tried some mathematical factors like sqrt(2) and pi unsuccessfully. The default points per inches is like the former but with about two times smaller image.


How can show the result of imagesc using imshow with magnification?

The basic idea seems to be that you want to create an RGB image that is a version of what is displayed on your screen using imagesc without actually saving it to disk first. There are a couple of accomplish this.

getframe

It is possible to grab a simple screenshot of the current axes using getframe . This will return a structure that has two fields: cdata and colormap . The cdata field is an RGB representation of the figure you specify (or gcf if you don't specify).

fr = getframe(hfig);
rgbImage = fr.cdata;

The downside of this approach is that the resolution of the output of getframe is simply the size of the figure (in pixels). If you are displaying a very large image on a small screen, you are obviously going to lose a lot of detail in the resulting image.

print

The built-in print function is typically used to send information to a printer or image file; however you can specify the output device to be -RGBImage and this will return an RGB version as the output.

rgbImage = print(hfig, '-RGBImage');

The real benefit of using print is that you can control the resolution of the output image as well as a number of other factors.

biggerRGB = print(hfig, '-RGBImage', '-r300');  % 300 dpi

If, when you create your figure, you are sure to specify the size (in inches), the result of this operation will be the same size regardless of what machine you may be using at the time.

hfig = figure('Units', 'inches', 'Position', [0 0 10 10]);

Using this combined with the -r300 above, the result will always be 3000x3000 pixels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM