필터 지우기
필터 지우기

About imwrite

조회 수: 3 (최근 30일)
Andre Asfar
Andre Asfar 2011년 6월 5일
Hi everyone I have a trouble about imwrite I have the code:
sav=imagesc(ycbcr2rgb(getsnapshot(handles.objVideo))); imwrite(sav,'im.bmp')
In a button in my gui, I want to save a image taken by the webcam with this command but the image saved just show me one pixel, what could be wrong? thanks a lot!

답변 (1개)

Walter Roberson
Walter Roberson 2011년 6월 5일
imagesc() returns the handle to the image object. You are then writing that handle as if it were the image itself.
Extracting the data from the handle by using get(sav,'CData') will not work: imagesc stores the original data (as returned by ycrcb2rgb()) and does its coloring tricks by setting the image object to use colormap interpolation.
In order to save the scaled image, you either need to getframe() the scaled image and save that, or you need to do the scaling yourself. If you do the scaling yourself, you do not need the imagesc() step.
To scale the image yourself, subtract the minimum value of the image from the entire image, and then divide the result by the range of values. You will now have an array that is in the range 0 to 1. Multiply by (the size of your colormap minus one) and uint8() or uint16() the result. ind2rgb() that to get the color version. Scale to uint8 or uint16 and imwrite() the result.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by