How to save matrix to workspace instead of plotting using imagesc function
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I don't understand how imagesc function works (scales), but my images plotted using via that function look better than using imshow. Is there any way to save the scaled image in the workspace instead of displaying it? I tried to debug built-in imagesc.m, but found nothing that scales data. If anyone knows how it's done, please, let me know.
채택된 답변
If M is your image, then
minM = min(M(:));
maxM = max(M(:));
scaledM = (M - minM) ./ (maxM - minM);
This will be in the range 0 to 1, so if you want to work with uint8 then uint8(scaledM .* 255)
댓글 수: 8
Thank's Walter, works well for me.
I need to save the image that shows by imagesc. Walter answer works, but it's giving me the scale of the original image which I don't want. My question is how can I save the image with the new scale shows in imagesc. in this case im-sim is original image, and info.x and info.y is the scale I need. for example the size of im_sim image is 479*616, but info.x and info.y is changing it to 140*180. Then, I need to save the image which include all frames as im-sim does have 54 frames. the image is uint8.
clc
clear
close all
load im_sim
load info
for fr =1:size(im_sim,3);
clf;imagesc(info.x,info.y,im_sim(:,:,fr)),colormap gray, axis image,
hold on; title(num2str(fr));
pause(0.05);
F = getframe ;
end
Thank you very much.
imresize() the scaled image.
Note: I have found that instead of manually calculating the ranges, that the intensity rescaling can be done by the mat2gray() call.
Thank you very much Walter for your reply. I tried before imresize(), the size is what I need, but the image is totally changed, and I loss many information of that image.
As you recommended I tried I = mat2gray(im_sim); but the size is same as im_sim image which I don't want. In fact, when I execute this line
imagesc(info.x,info.y,im_sim(:,:,fr)),colormap gray, axis image,
it's showing the size I need, but I don't know how can I save this imagesc as a image with all frames. size of im_sim(479*616*54) size info.x = 1*616 size info.y = 1*479 but the size of imagesc result is 140*180 which I need to save the image with this size without losing information. Thanks a lot
Please attach the data for a sample image that is "totally changed" by the imresize()
Thanks a lot Walter for your reply. Unfortunately, I'm not allow to share the data because of confidentiality. just I can attach the values of info.x and info.y. The size of image with this info.x and info.y turned to 140*180 which I need to save the image with this size. I tried
I = imresize(im_sim,[140 180]);
but as I said I lost information and quality of image changed. In fact this image is my ground truth image, and I need exactly as it is to test my algorithm. I tried
im = imagesc(info.x,info.y,im_sim(:,:,fr)),colormap gray, axis image,
imwrite(im.CData);
G = [im(:).CData];
but again giving the image with 479*616 size. Thank you
When you use a vector of xdata or ydata for an image() or imagesc() call, all the entries are ignored except for the first and last entries. So your call is equivalent to
imagesc([0, 180.283902162354], [0, 140.292887029289], im_sim(:,:,fr))
Now, that does not tell it to plot into a 140 x 180 area: it tells it to place the lower left pixel center at data units [0, 0] and the upper right pixel center at data units [180.28, 140.29]. The actual number of pixels used on the screen depends upon the size of the axis. If imresize() is losing too much information for your purposes, then you are almost certainly relying on the fact that the displayed image is displaying more than one pixel per data unit.
You need to decide whether you need the final result to be 140 x 180 or if you need the final result to be some intermediate size between 140 x 180 and 479 x 616. Once you decide on the appropriate output size then you can imresize() to it.
Thanks a lot Walter for clarify about info files.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
태그
참고 항목
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)
