About imwrite

2 visualizaciones (últimos 30 días)
Andre Asfar
Andre Asfar el 5 de Jun. de 2011
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!

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Jun. de 2011
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.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by