how to index a 3D image
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stephen Devlin
el 21 de Ag. de 2018
Respondida: Yuvaraj Venkataswamy
el 21 de Ag. de 2018
Hi, I have an RGB tif image (no map) of some color bars (it wouldn't let me upload a tif). It is 77x300x30, each of the color bars is approximately 20 columns of data. I have taken the middle column out of each of the color bars and saved them to a new array, and then show it as an image. I tried a for loop and got nowhere with it, now I am trying to index it with an array but I am sure there is a more straightforward method than the longhand way I have used, any ideas?
clear all
close all
clc
img = imread('spectrum11.jpg');
imwrite(img, 'spectrum11.tiff');
%%==============================================
[B,map]=imread('spectrum11.tiff');
slice=B(1:10,:,:);
subplot(3,1,1)
imshow(B)
title('original spectrum11 pic')
subplot(3,1,2)
imshow(slice)
title('sliver of the spectrum')
%show a few rows of the image
slice_data=slice(1,:,:);
[r,c,d]=size(slice_data)
%%take the middle 5 columns of each colour bar from the slice_data.
%preallocate an array
spec=zeros(1,45,3);
%get an index for the middle of each color bar
ind=zeros(15,1,3)
ind_nums=(10:20:300)'
ind(:,1,1)=ind_nums;
ind(:,1,2)=ind_nums;
ind(:,1,3)=ind_nums;
%use index to extract the data from each of the RGB layers of slice_data
slice_data_1=slice_data(:,:,1);
slice_data_2=slice_data(:,:,2);
slice_data_3=slice_data(:,:,3);
A1=slice_data_1(ind(:,:,1));
A2=slice_data_2(ind(:,:,2));
A3=slice_data_3(ind(:,:,3));
A=zeros(1,15,3);
A(:,:,1)=A1;
A(:,:,2)=A2;
A(:,:,3)=A3;
Au=uint8(A);
subplot(3,1,3)
imshow(Au)
0 comentarios
Respuesta aceptada
Yuvaraj Venkataswamy
el 21 de Ag. de 2018
@Stephen Devlin: For this also, you can see the below link.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!