Image from a 1x1Byte[] .NET Object

1 view (last 30 days)
Nom
Nom on 14 May 2020
Edited: Henry Barth on 16 Mar 2021
Hello,
So I get a 1x1 Byte[] called imageHandle that is meant to hold a bitmap image (I believe it's meant to be a 448x501x3 uint8 variable). However when I run the following code:
uintVar = uint8(imageHandle);
I get ans = 1x897832 uint8.
Is there some sort of function I should be running in arrange these bits into a viewable image?
I have attached the uintVar.mat file, was not able to attach the imageHandle variable as matlab doesn't load .NET objects from a .mat file.
  6 Comments
Nom
Nom on 14 May 2020
Oh crap I am so sorry, I didn't realize I forgot to attach the .mat file entirely!
I attached the uintVar var file which is the 1x897832 uint8.
I also attached the imageHandle.mat which is the system.Byte[] in question, but matlab doesn't let you load it in as a .NET object.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 15 May 2020
Edited: Walter Roberson on 15 May 2020
cols = 501; rows = 448;
RGBA = flipud(permute(reshape(uintVar(41:end),4,cols,rows),[3 2 1]));
imshow(RGBA(:,:,1:3))
  9 Comments
Henry Barth
Henry Barth on 16 Mar 2021
Edited: Henry Barth on 16 Mar 2021
I assume you are reading this image data from an omicron system over the supplied .NET interface. The bytestream contains only the second header of the bitmap format described on wikipedia so you have to subtract these offset values by 14 (13 for matlab). The fourth channel only consists of 255 except for to highest row as well as the left-most column. You can eliminate that using:
bmpArrayCorrected = RGBA(:,:,1:3);
rChannel = RGBA(:,:,1);
gChannel = RGBA(:,:,2);
bChannel = RGBA(:,:,3);
rChannel(1,:) = mode(rChannel,'all');
rChannel(:,1) = mode(rChannel,'all');
gChannel(1,:) = mode(gChannel,'all');
gChannel(:,1) = mode(gChannel,'all');
bChannel(1,:) = mode(bChannel,'all');
bChannel(:,1) = mode(bChannel,'all');
% r and b channels are swapped in omicron data, swap them
bmpArrayCorrected(:,:,3) = rChannel;
bmpArrayCorrected(:,:,2) = gChannel;
bmpArrayCorrected(:,:,1) = bChannel;

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!