MATLAB Answers

how to index a 3D image

조회 수: 11(최근 30일)
Stephen Devlin
Stephen Devlin 21 Aug 2018
답변: Yuvaraj V 21 Aug 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

로그인 to comment.

채택된 답변

Yuvaraj V
Yuvaraj V 21 Aug 2018

  댓글 수: 0

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by