-2

I'm using step function to read frames from a video (using vision.VideoFileReader), the image result is a Bayer one and three dimensions, the problem is that I can't move from Bayer to grayscale using 'demosaic' function. The image that I obtained is from 0-1.

to explain more : When I show size of image I obtain [1024 1024 3], normally I use demosaic to move from Bayer to RGB and then from RGB to grayscale. The demosaic function is apllied on an image 2D.

Code :

function obj = setupSystemObjects2()

    obj.reader = vision.VideoFileReader(video);
    obj.videoPlayer = vision.VideoPlayer('Position', [20, 400, 700, 400]);

end

function frame = readFrame()

    frame = obj.reader.step();
end

Thanks for help.

Shai
  • 111,146
  • 38
  • 238
  • 371
Ayoub
  • 11
  • 1
  • You can't move to real grayscale? Does that sentence make ANY sense? Do you have a fake grayscale? Imaginary? What is real grayscale? Please explain what you are trying to do. – Ander Biguri Jul 14 '14 at 11:41
  • I wanna have an image which their values are between 0 and 255, after using step I don't get what I want @AnderBiguri – Ayoub Jul 14 '14 at 11:47
  • 1
    Post some code. You dont get what you want? what does that means? you get an error? you get an image from 0-1? I mean, without any information you may be getting the perfect representation of PI, but we dont know... You need to give us more information. Show us some results, give us some code, or somehting. Its absolutely iposible we are able to answer your question with the information you gave. Plus, as you see, your question is going to be closed because its too low quality unless you give us more. – Ander Biguri Jul 14 '14 at 11:52
  • @AnderBiguri I hope that is clear now – Ayoub Jul 14 '14 at 12:07

2 Answers2

1

It seems like the frame you read is not in Bayer format and does not require demosaicing.
Try using rgb2gray:

gImg = rgb2gray( frame );
Shai
  • 111,146
  • 38
  • 238
  • 371
  • I used rgb2gray but it doesn't give an image from 0 to 255 – Ayoub Jul 14 '14 at 12:12
  • @Ayoub what is the data type of `frame`? is it `double`, `single` or `uint8`? if you are working with floating point representation of images (i.e., `double` or `single`) then you should expect pixel intensities to range between 0 and 1 and NOT 255. you can scale the range by using `im2uint8` or simply by multiplying by 255. – Shai Jul 14 '14 at 12:15
  • I tried to multiply by 255 but it doesn't wok I get a white image after – Ayoub Jul 14 '14 at 12:26
1

As far as I know, vision.VideoFileReader, will not give you Bayer format. It reads standard video formats, and the fact that you are getting frames of size [1024 1024 3] suggests that the frame is RGB. Try displaying a frame using imshow to see if it makes any sense. If it looks the way you expect it to look, then just use rgb2gray if you need to convert to grayscale.

Note about the fact that your pixel values range between 0 and 1. vision.VideoFileReader gives you frames of class 'single' by default. If you want 'uint8' frames that range between 0 and 255, set the 'VideoOutputDataType' property to 'uint8':

obj.reader = vision.VideoFileReader(video, 'VideoOutputDataType', 'uint8');
Dima
  • 38,860
  • 14
  • 75
  • 115
  • Thanks for the line code I've resolved the problem of values, but now I still have the mosaic in the image – Ayoub Jul 14 '14 at 12:42