can you plot a image? (line by line or pixel by pixel)

for this matrix:
>> A=rand(10,7)
>> A=im2bw(A)
Can you write a code like this? And with this method to write an image of the matrix A?(This is a simple form of what is going)
>> for i=1:10
>> for j=1:7
>> imshow(A(i,j))
>> end
>> end
And finally the results are similar to this picture?
>> imshow(A)

Réponses (4)

Teja Muppirala
Teja Muppirala le 17 Juil 2012
Modifié(e) : Teja Muppirala le 17 Juil 2012
One idea would be to use the AlphaData property. This sets the transparency of each pixel:
A = im2bw(rand(10,7));
M = zeros(size(A'));
h = imshow(A, 'InitialMagnification' ,2000);
for n = 1:numel(M);
M(n) = 1;
set(h,'AlphaData',M');
drawnow;
end

11 commentaires

This might be suitable for Fetemeh's needs. It does not exactly match the question, though, in that it builds the entire image at once, but then reveals it a bit at a time, whereas the question involved building the image a bit at a time.
There is a slight modification possible to the approach: as long as the size of the image is known ahead of time, the CData property can be changed as you go, with the pixels whose values are unknown essentially being ignored because their AlphaData is 0.
Modifying the example slightly:
A = zeros(10,7);
M = zeros(size(A));
h = imshow(A, 'InitialMagnification' ,2000);
for n = 1:numel(M);
A(n) = rand; %emulating not knowing it ahead of time
M(n) = 1; %expose it to view
set(h, 'Cdata', A, 'AlphaData', M);
drawnow;
end
Fatima prv
Fatima prv le 17 Juil 2012
Modifié(e) : Fatima prv le 17 Juil 2012
I aim is showing each pixel that want.
Fatima prv
Fatima prv le 17 Juil 2012
Modifié(e) : Fatima prv le 17 Juil 2012
Really good. But I do not want to row or column. If I want from center of my screen and the radial, what is?
Walter Roberson
Walter Roberson le 17 Juil 2012
Modifié(e) : Walter Roberson le 17 Juil 2012
radial -- are you trying to do a "live" sonar scope?
You can calculate a pixel order to reveal. For example,
rows = size(YourImage,1);
cols = size(YourImage,2);
[X, Y] = ndgrid(1: rows, 1 : cols);
[sortedvals, pixelorder] = sort((X(:)-rows/2).^2 + (Y(:)-cols/2).^2);
M = zeros(size(YourImage));
h = imshow(YourImage, 'InitialMagnification' ,2000);
for n = pixelorder
M(n) = 1;
set(h, 'AlphaData', M);
drawnow;
end
The order used in this code would more or less spiral outwards from the center (but probably not exactly so.)
Fatima prv
Fatima prv le 17 Juil 2012
h , A=?
Walter Roberson
Walter Roberson le 17 Juil 2012
Modifié(e) : Walter Roberson le 17 Juil 2012
I have adjusted the code, above.
Fatima prv
Fatima prv le 19 Juil 2012
for radar display not sonar scope :)
Fatima prv
Fatima prv le 19 Juil 2012
It is possible to increase speed?( in Teja's code)
Walter Roberson
Walter Roberson le 19 Juil 2012
Modifié(e) : Walter Roberson le 19 Juil 2012
You can turn on groups of pixels at the same time. For example,
A = im2bw(rand(10,7));
M = zeros(size(A'));
h = imshow(A, 'InitialMagnification' ,2000);
for n = 1:size(A,1);
M(n,:) = 1;
set(h,'AlphaData',M');
drawnow;
end
Fatima prv
Fatima prv le 20 Juil 2012
Modifié(e) : Fatima prv le 20 Juil 2012
this code has a error :
Warning: Dimensions of AlphaData must be 1x1, or must match CData..
what mean?
It means that for no good reason that I can see, Teja transposed M when building it, and transposed again when using it, but that I did not take that into account when I adjusted Teja's code.
A = im2bw(rand(10,7));
M = zeros(size(A'));
h = imshow(A, 'InitialMagnification' ,2000);
for n = 1:size(A,1);
M(:,n) = 1; %corrected line
set(h,'AlphaData',M');
drawnow;
end
I would not have written the code this way myself, but you did specifically ask for the speed up to be against Teja's code.

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 17 Juil 2012

0 votes

Yes, it is possible, just very very inefficient. You can create one patch object per pixel, with the edge turned off, and the facecolor set to the pixel color. This is the closest thing MATLAB has to a pixel object.
It might take a few hours to render a single image this way: MATLAB is not designed for efficiency when it comes to having thousands of graphics objects on a single figure.

3 commentaires

Fatima prv
Fatima prv le 17 Juil 2012
yes but i need to display a image with delay.
You would certainly get delays if you used this mechanism ;-)
Fatima prv
Fatima prv le 17 Juil 2012
Modifié(e) : Fatima prv le 17 Juil 2012
I write this code, but I can not see where I'm going to put every pixel
A=rand(10,7)
A=im2bw(A)
s=size(A);s=s/2;
for i=1:10
for j=1:7
x=[((-1/7)*s(2))+.5*i (s(2)./7)+.5*i];
y=[((-.1)*s(1))+.5*j (s(1)./10)+.5*j];
image(A(i,j),'XData',x,'YData',y), axis image,
hold on
end
end

Connectez-vous pour commenter.

Fatima prv
Fatima prv le 22 Juil 2012

0 votes

in a image :Can I change data of a pixel ? without drawing all of picture again, and re show only one pixel?

1 commentaire

Normally, if you change the CData property of the image, all of the changes show up simultaneously (unless possibly the figure has many many objects in it.)
This behavior can be changed by altering the "erasemode" property of individual graphic objects; see for example the description of erasemode for lines
Images also have erasemode but note that there is no provided method to change only individual pixels, no way to say "change the pixel at (172,48) to green": one can only set the entire CData at once. The erasemode properties of images is more about what should happen if you move or resize or delete the image as a whole.
MATLAB's graphics model is not pixel-oriented. There is no (documented) user-accessible frame buffer.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 22 Juil 2012

0 votes

Why do you want to do this? Plot one pixel at a time? Your code shows one pixel only, not a whole image with just one pixel in the image changing. Maybe you'd be interested in the FAQ about making a movie of your data: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_a_movie_from_my_MATLAB_figures.3F

2 commentaires

Fatameh is attempted to produce a "radar scope" effect where updates happen along a sweeping line.
Fatima prv
Fatima prv le 27 Juil 2012
yes.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Tags

Question posée :

le 17 Juil 2012

Community Treasure Hunt

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

Start Hunting!

Translated by