显示 更早的评论
Hellow, i have reconstruct an image of 16x16 pixels and all the pixels are in a vector of 256 elements P(256) , is it necessary to change P to a dimension P(16,16) to show it in an image. I thought it would but i tried it and it gives a error. Hope for a positive answer :)
采纳的回答
image(reshape(P,16,16))
What error are you getting?
10 个评论
I tried this and the error is:
figure
image(reshape(X,16,16))
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
Is it always necessary to reshape, because all the images i produce in my ART code have the form: I(x,1) where x is mostly 256,512 or 1024 and maybe you know there is a standard solution?
So show the output of this, placed right before the line that errors:
size(X)
If you have an array which is 512 or 1024, then that contradicts your initial claim that "all the pixels are in a vector of 256 elements P(256)"
If you _do_ have 512 or 1024 elements, then what outcome do you want? Still a 16 x 16 pixel outcome? If so then how do you want multiple input elements to be mapped in to the 16 x 16 output ?
No, in my program the user can choice how many pixels. And i must visualize the result. So if they select a 1024 image, i must image the vector with 1024 elements (thats a 32x32 pixel image). So i though that i must make it 32x32 to use it in image. Because image(vector) doesn't do anything...
Also when the user choice a 256(16x16) image, i also have to image it... so i need it in general.
I hope you understand it now :)
But already thank you very much!
L = sqrt(length(P));
if floor(L)~=L
error('Bad vector length.')
else
image(reshape(P,L,L))
end
The only thing I might do differently than Matt's answer is to use numel(P) instead of length(P)
@Walter, just out of curiosity why choose NUMEL over LENGTH?
Are you still suspicious that Fiboehh hasn't supplied a vector?
numel() covers the case where a non-vector was supplied but length() does not. numel() is as easy to write and covers more cases, so one might as well use it unless one explicitly wishes the code to error out in the case where a non-vector was supplied (and if so then why not test for that condition to make it obvious that one did not simply "overlook" that possibility ?)
That and I don't want to have another go around with someone saying, "But that failed for me" only to have it turn out that they had supplied a non-vector.
Exactly as I thought... Good enough!
Note that 512 does not have an integer square root. Fiboehh, what do you want to have happen if 512 is selected?
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
