Image from a 1x1Byte[] .NET Object

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 commentaires

Walter Roberson
Walter Roberson le 14 Mai 2020
it appears to have a 40 byte header and 4 bytes per pixel, such as rgba
Nom
Nom le 14 Mai 2020
I honestly have no idea, I'm just being told it's a device-independent bitmap which is said to be no different than a .bmp format
Nom
Nom le 14 Mai 2020
I think this has more to do with how to read .NET data in matlab, Sorry I wasn't able to provide more information Walter. I'm not so sure about this stuff myself.
Walter Roberson
Walter Roberson le 14 Mai 2020
There is no such thing as a device-independent bitmap, not really. bitmaps are inherently raster oriented, and that makes them device dependent. .bmp are not device independent either. Device independent is a pain to do.
If you had color information that was device-independent then when properly rendered it would appear as the same color on all displays, even if they used different display technologies such as CRT vs LCD vs LED. If the stored information does not have a gamma map and color temperature information (better yet, spectral illumination information) then it is not device independent.
Anyhow, the .mat file did not get attached :(
Nom
Nom le 14 Mai 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.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 15 Mai 2020
Modifié(e) : Walter Roberson le 15 Mai 2020

0 votes

cols = 501; rows = 448;
RGBA = flipud(permute(reshape(uintVar(41:end),4,cols,rows),[3 2 1]));
imshow(RGBA(:,:,1:3))

9 commentaires

Nom
Nom le 15 Mai 2020
Modifié(e) : Nom le 15 Mai 2020
Thank you for responding Walter,
running the imshow(RGBA) command I get:
Error using images.internal.imageDisplayValidateParams>validateCData (line 115)
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 241)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Runnning this line:
RGBA = flipud(permute(reshape(uintVar(41:end),4,rows,cols),[3 2 1]));
Gives me a 501x448x4 uint8 variable
Am I doing something wrong?
Nom
Nom le 15 Mai 2020
Modifié(e) : Nom le 16 Mai 2020
I think I'm really close to working this out.
So I removed the last dimension by 1 by using the following command:
RGBA(:,:,4:4) = [];
RGBA = 501x448x3;
Though some information is definitely lost as I have, what the image should look like vs. what I got from this matlab output.
I'm just not sure how to retain that information lost while keeping it a 501x448x3.
Maybe changing the resolution so it isn't a 501x448?
Nom
Nom le 15 Mai 2020
Modifié(e) : Nom le 15 Mai 2020
Sorry for the multiple edits, I think I may know why the MATLAB output is not exactly the same. Those diagonals lines we see are supposed to be the vertical lines, but the data needs to be shifted to the left I think...
I'm not sure how to go about this, I realize that a function needs to be created where the first row (of the picture) gets shifted by X and the next row by X+1 though I'm not sure how to implement this.
cols = 501;
rows = 448;
RGBA = flipud(permute(reshape(uintVar(41:end),4,rows,cols),[3 2 1]));
RGBA(:,:,4:4) = [];
for i = 0:rows
RGBA = circshift(RGBA,10+i,2);
end
imshow(RGBA)
I gave the above a try but it just ends up shifting the entire image together.
Walter Roberson
Walter Roberson le 15 Mai 2020
Sorry, I made mistakes when I transcribed from my working version to here; I went back and fixed my code, above.
Nom
Nom le 15 Mai 2020
Thank you so much Walter, here I was messing around more than I should have lol.
Thank you again, this works perfectly!
Nom
Nom le 27 Mai 2020
Modifié(e) : Nom le 27 Mai 2020
Just a follow-up question, if I didn't know what the resolution was meant to be. Would there be anyway I can still print out an accurate picture? Assuming uintVar is not 1x897832 uint8 and perhaps some other length.
i.e.(instead of cols = 501; rows = 448, they were some other values)
cols = typecast(uintVar(5:8), 'uint32');
rows = typecast(uintVar(9:12), 'uint32');
Nom
Nom le 27 Mai 2020
Thank you, learned a lot about image processing with this problem; all thanks to you.
Henry Barth
Henry Barth le 16 Mar 2021
Modifié(e) : Henry Barth le 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;

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Produits

Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by