conversion of data into bitmap

12 Ansichten (letzte 30 Tage)
Mathieu
Mathieu am 10 Jul. 2015
Kommentiert: Mathieu am 17 Jul. 2015
Hello,
I am actually working on Matlab R2015a. I would like to know if it is possible to plot an image from data? I explain:
I have for example a matrix composed by 4000 signals of 128 samples (so a matrix 4000x128) and the data is on 12 bit (from -2048 to +2047). By using the imagesc function (to have a gray image), I have an "image" view of my data. But I plot this on a GUI and added a slide barre to select the signal in order to plot on another figure (for example the barre is on the 1287th signal so the second plot corresponds to this last). When I slide the barre, using Matlab functions, I success to actualize the second figure (the one who plot only one signal). But the deplacement of the barre is slow, I think because of the size of my data. So I thought that convert my data into a bitmap image could be ameliore the speed of my GUI.
I precise I haven't the image processing toolbox. Maybe I am wrong and it is slow just because of the imagesc function?
I thank you in advance for your help. Best regards

Akzeptierte Antwort

Image Analyst
Image Analyst am 15 Jul. 2015
I'm not seeing the scroll bars. How do you move the red line to a new place? Do you click on the image to put it in a different place, or do you move a scroll bar/slider? When you move the red line, you have to delete the handle of the prior line, and then draw the new line with the line function:
yLimits = ylim();
try
delete(hLine); % Delete prior line if it exists.
catch
% No prior line. Nothing in catch so just ignore error.
end
hLine = line([x, x], yLimits, 'Color', 'r');
I don't think imagesc is the problem but you can try imshow() instead. It's now in base MATLAB, not just the Image Processing Toolbox.
Your data, 4000x128 is not large at all - just a small fraction of the size of a typical run-of-the-mill digital image. So the size of your data should not be a problem.
  5 Kommentare
Image Analyst
Image Analyst am 16 Jul. 2015
Yes, in some apps I use a scrollbar to move the line around. In another app, if the user clicks on a point in the image, I (re)draw a box, using either rectangle() or plot() or line() (I don't remember), with the upper left corner of the box at the place where the user clicked. Both are very fast.
Mathieu
Mathieu am 17 Jul. 2015
Ok So I tried something else because I don't succeed to use correctly your solution. I tried not to plot one of the 3 figures, and it is now fast enough. In reality at each updating I am doing some calculations before to plot this figure and I think it is that which slow down the slide of the scrollbar because the speed increase when I don't do these calculations.
So thank you for your help because in the future I probably do like you.
Best regards.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 11 Jul. 2015
Changing your data into a bitmap is not likely to help in this situation.
You will need to show us your code for using a slider to select the signal to plot.

Mathieu
Mathieu am 15 Jul. 2015
Hello,
I add the image of my interface :
On the left, you have the "map" composed by (here) 100 signals of 512 samples (length of each signal, called also sig_length). On the right on the top you have the selected signal. Using the scroll of the mouse on this figure, or modifying the edit box on the right top or again with the pushbutton +/-, the display is updated with the function updating_fcn. The figure on the right on the bottom is another signal (the result of some operations on the signal above) and this one is automatically updated with the one above.
Like I said before, for the figures on the right, there is an updating each time that there is an action on the interface (button pushed, text on edit box changed, line slided). The left figure is "blocked" in the updating to avoid useless computation.
Then, I added a barre on the left figure to select the signal more easily than the edit box. To do that, I first create the line on the updating_fcn when the interface is opened for the first time :
if (selec_sig == 0)
line('Parent', fig_handles(3), 'XData', [1 1], 'YData', [0 sig_length], 'Color', 'red', 'linewidth', 3, ...
'Tag', 'ligne');
else
line('Parent', fig_handles(3), 'XData', [selec_sig selec_sig], 'YData', [0 sig_length], 'Color', 'red', 'linewidth', 3, ...
'Tag', 'ligne');
end
To be able to slide the line, I use Matlab functions which are called when we push and relax the left button of the mouse (on the .m file of the interface I created with GUIDE) :
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
set(gcbf, 'WindowButtonMotionFcn', @draggingFcn);
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
set(gcbf, 'WindowButtonMotionFcn', '');
updating_fcn();
  1 Kommentar
Mathieu
Mathieu am 15 Jul. 2015
Bearbeitet: Mathieu am 15 Jul. 2015
Finally, the draggingFcn is the next one :
function draggingFcn(varargin)
global nb_signaux flag_refresh
h0 = gco;
h = findobj(gcf, 'Tag', 'ligne');
if h0 == h
aH = findobj(gcf,'type','axes');
% 1 right bottom, 2 right top, 3 left
h = findobj(gcf, 'tag', 'ligne');
pt = get(aH(3), 'CurrentPoint');
pos = floor(pt(1,1));
% To be sure the line stay in the map
if pos > nb_signaux
pos = nb_signaux;
pt(:,1) = nb_signaux;
else if pos < 1
pos = 1;
pt(:,1) = 1;
end
end
% Updating of the position of the line
set(h, 'XData', pt(1)*[1 1]);
% Updating of the edit box of the selected signal
set(findobj(gcbf,'tag','choix_signal'), 'String', num2str(floor(pt(1,1))));
% Flag to avoid the updating of the left figure
flag_refresh = 0;
% Updating of the right figure
updating_fcn()
end
The if condition is to modify the selected signal only if we click on the line. Do you need some extra information to understand what I wanted to do?
Thanks in advance for your help ;)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by